Skip to content

Conversation

@bblommers
Copy link

Motivation

The PluginManager already had decent type hints - this PR improves them a bit and adds support for mypy to verify that they are all correct.

Note that I added type hints to the test as well, just to verify the type hints of the PluginManager itself are correct when invoking the class.

Ideally I'd like to get to a point where we add types to the entire code base, just to make it a little easier to use downstream. When we get to that point, we can add the py.typed file as well.

"""
try:
return func(*args)
func(*args, **{})
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the invocations of _call_safe do anything with the result, so I think this is a safe refactor/improvement

def test_lifecycle_listener(self, dummy_plugin_finder):
listener = MagicMock()
def test_lifecycle_listener(self, dummy_plugin_finder: DummyPluginFinder) -> None:
listener = Mock()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the PluginManager I also made this change:

- if isinstance(listener, (list, set, tuple)):
+ if isinstance(listener, Iterable):

Turns out that MagicMock is an instance of Iterable - so that suddenly changed the logic, and cause the test to fail. Using a basic Mock does not have this problem.

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 this pull request may close these issues.

2 participants