Skip to content

__getattr__ should raise AttributeError, not EventsException #17

@DavidCurtiss

Description

@DavidCurtiss

When __getattr__ raises an EventsException for a missing attribute, it breaks getattr(obj, name, default).

Simple test that reproduces it:

class TestGetattr(TestBase):

    def test_getattr(self):
        events = Events(('on_event', ))
        assert getattr(events, "blah", None) is None

This is a problem for me because in python 3.8, creating a Mock of an object that has events runs into this issue. Here's the corresponding test case for python 3.8:

class TestMocking(TestBase):

    def test_mock(self):
        class MyEvents(Events):
            __events__ = ('on_eventOne', )
            _instance = None

        MyEvents._instance = MyEvents()

        # In python 3.8, this results in "EventsException: Event '_is_coroutine' is not declared"
        unittest.mock.Mock(MyEvents)

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