Skip to content

Python 3.13 adds new class attributes: __firstlineno__ and __static_attributes__, resulting in failing test_reserved_attributes #103

Description

@befeleme

The tests fail with Python 3.13.0b1 with the traceback below.

per https://docs.python.org/dev/whatsnew/3.13.html:

  • __firstlineno__ is the line number of the first line of the class definition
  • __static_attributes__ is a tuple of names of attributes of this class which are accessed through self.X from any function in its body. For munch, the value is ('update', '__class__'), but I'm not entirely sure it's fixed.
=================================== FAILURES ===================================
__________________ test_reserved_attributes[__firstlineno__] ___________________

attrname = '__firstlineno__'

    @pytest.mark.parametrize("attrname", dir(Munch))
    def test_reserved_attributes(attrname):
        # Make sure that the default attributes on the Munch instance are
        # accessible.
    
        taken_munch = Munch(**{attrname: 'abc123'})
    
        # Make sure that the attribute is determined as in the filled collection...
        assert attrname in taken_munch
    
        # ...and that it is available using key access...
        assert taken_munch[attrname] == 'abc123'
    
        # ...but that it is not available using attribute access.
        attr = getattr(taken_munch, attrname)
        assert attr != 'abc123'
    
        empty_munch = Munch()
    
        # Make sure that the attribute is not seen contained in the empty
        # collection...
        assert attrname not in empty_munch
    
        # ...and that the attr is of the correct original type.
        attr = getattr(empty_munch, attrname)
        if attrname == '__doc__':
            assert isinstance(attr, str)
        elif attrname in ('__hash__', '__weakref__'):
            assert attr is None
        elif attrname == '__module__':
            assert attr == 'munch'
        elif attrname == '__dict__':
            assert attr == {}
        else:
>           assert callable(attr)
E           assert False
E            +  where False = callable(35)

tests/test_munch.py:229: AssertionError
_______________ test_reserved_attributes[__static_attributes__] ________________

attrname = '__static_attributes__'

    @pytest.mark.parametrize("attrname", dir(Munch))
    def test_reserved_attributes(attrname):
        # Make sure that the default attributes on the Munch instance are
        # accessible.
    
        taken_munch = Munch(**{attrname: 'abc123'})
    
        # Make sure that the attribute is determined as in the filled collection...
        assert attrname in taken_munch
    
        # ...and that it is available using key access...
        assert taken_munch[attrname] == 'abc123'
    
        # ...but that it is not available using attribute access.
        attr = getattr(taken_munch, attrname)
        assert attr != 'abc123'
    
        empty_munch = Munch()
    
        # Make sure that the attribute is not seen contained in the empty
        # collection...
        assert attrname not in empty_munch
    
        # ...and that the attr is of the correct original type.
        attr = getattr(empty_munch, attrname)
        if attrname == '__doc__':
            assert isinstance(attr, str)
        elif attrname in ('__hash__', '__weakref__'):
            assert attr is None
        elif attrname == '__module__':
            assert attr == 'munch'
        elif attrname == '__dict__':
            assert attr == {}
        else:
>           assert callable(attr)
E           AssertionError: assert False
E            +  where False = callable(('update', '__class__'))

tests/test_munch.py:229: AssertionError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions