Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
befeleme opened this issue Jun 5, 2024 · 0 comments · May be fixed by #104

Comments

@befeleme
Copy link

befeleme commented Jun 5, 2024

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
@befeleme befeleme linked a pull request Jun 5, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant