-
Notifications
You must be signed in to change notification settings - Fork 0
Chore: Correct and verify type hints in manager.py #41
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
base: main
Are you sure you want to change the base?
Conversation
| """ | ||
| try: | ||
| return func(*args) | ||
| func(*args, **{}) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, could we specify the Callable as [PS, None]? Or - to keep the return, use -> T | None?
| def test_lifecycle_listener(self, dummy_plugin_finder): | ||
| listener = MagicMock() | ||
| def test_lifecycle_listener(self, dummy_plugin_finder: DummyPluginFinder) -> None: | ||
| listener = Mock() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I wonder if we should just narrow down the supported types on the interface instead - but I agree with not making any outward facing changes to the API in this PR, so this change is fine with me. We could have also just wrapped it in a list from the start, but I think it's fine like this!
dfangl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You captured a lot of typing issues, nicely done! LGTM!
| """ | ||
| try: | ||
| return func(*args) | ||
| func(*args, **{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, could we specify the Callable as [PS, None]? Or - to keep the return, use -> T | None?
| def test_lifecycle_listener(self, dummy_plugin_finder): | ||
| listener = MagicMock() | ||
| def test_lifecycle_listener(self, dummy_plugin_finder: DummyPluginFinder) -> None: | ||
| listener = Mock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I wonder if we should just narrow down the supported types on the interface instead - but I agree with not making any outward facing changes to the API in this PR, so this change is fine with me. We could have also just wrapped it in a list from the start, but I think it's fine like this!
3c5fc3b to
84924a5
Compare
Motivation
The
PluginManageralready had decent type hints - this PR improves them a bit and adds support formypyto 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
PluginManageritself 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.typedfile as well.