-
-
Notifications
You must be signed in to change notification settings - Fork 147
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
Full type annotations #199
Conversation
@nicoddemus I did a bunch of improvements over my initial PR #194 |
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.
Thanks @svenstaro for pursuing this!
However in order to close #152 we need to:
- Properly annotate all public methods that are part of the API.
- Add an empty
py.typed
file along with the package, to let static checkers know that this package provides type annotations. - Mention this in the README.
So I'm OK with merging this as is because it annotates a few functions already, but in order to close #152 we have more work to do here. 👍
Co-authored-by: Bruno Oliveira <[email protected]>
@nicoddemus there is a problem with the changes you suggested. Since PS.: I have also added py.typed. |
Hey @staticdev !
Returning
We can declare those functions as returning def spy(self, obj: object, name: str) -> unittest.mock.MagicMock:
...
spy_obj = self.patch.object(obj, name, side_effect=wrapped, autospec=autospec)
spy_obj.spy_return = None
spy_obj.spy_exception = None
return cast(unittest.mock.MagicMock, spy_obj) (We also need to import This works because both the standalone Also we should document the other public functions with full arguments, for example
Thanks! We however also need to include that file in the package to signal the type checker that this module provides type annotations: https://www.python.org/dev/peps/pep-0561/#id18. I understand this might seem quite a bit more work than it was thought initially, but I suspect it is needed to make the type annotations as useful as possible for users. I plan to tackle the issues above soon in case you don't have to work on them, probably in the next few days. Thanks again all the work done so far. |
Hi @nicoddemus, About your last message:
|
I see, thanks @staticdev! I will take a look at the problems later then. 👍 |
Closes #152