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
please help how to correctly type annotate a wrapt decorator .... #164
Comments
I don't know how to use type annotations, so don't really understand what you are trying to do and have no immediate idea. Can you expand more on how it is meant to all work and what for? May or may not be relevant, but also look at using an adapter prototype function if need to have a different signature/annotations for a target function be exported. It is also quite possible that the function wrapper in wrapt isn't passing back annotations information correct since was written before they were introduced and never used them. Is there more than |
Dear Graham, I try to archive that mypy passes - but it does not. The decorator itself works without Problems. The whole thing is to to mock a C Librarary (winreg) that only accepts positional arguments. Since it seems to be impossible within a function to find out if a parameter was passed as argument or as I guess that this type annotation has to happen in wrapt, because You do a lot of magic there, In general I have the opinion its totally worth to use type annotations especially on bigger projects, MAYBE I can solve it by making a stub file for the wrapt decorator, I will try it after my second coffee. All the best and thanks for Your great work and fast reply. Robert, Vienna |
Dear Graham, You can type annotate a third party package with stub files, which I did for the decorator function of wrapt.
mypy can pass now (I read in the wrapt issues some users asking for that) It would be really cool if You consider to make wrapt a PEP561 package, in order to be able to use mypy with it, I guess, it would be enough to use my suggested You dont need to fully annotate everything, wrapt.decorator would be a good starter . And if something happens not to be correct, users still can use the This would make Its not nice to take care for the 3rd party stubs, include the paths in the mypy path, etc - so it would be wonderful if that works out of the box. hoo roo Robert, Vienna |
@bitranox Any headway on the I seemed to make from typing import Any, Generic, TypeVar
T = TypeVar("T", bound=Any)
class ObjectProxy(Generic[T]):
__wrapped__ : T
def __init__(self, wrapped: T):
... |
If any solution requires adding annotation into the original wrapt source code, then it needs to wait until Python 2.7 support is dropped from wrapt. Besides that, I still don't know enough about annotations to know what changes would be required. |
Dear Graham, |
Graham, if You want I can make a PR and You test it ? |
I am hoping to set aside some time in coming week to catch up on some wrapt stuff, so if you can provide a PR to get me started that would be most helpful. I didn't previously understand your comment about stub files as I didn't know Python supported such a concept and thought annotations needed to be in the source code. |
@GrahamDumpleton Regarding your comment on it needs to wait until Python 2.7 support is dropped from wrapt, why can't you publish a separate branch without Python2 support? |
Would only do that after had dropped Python 2.7 support, and only if need to back port critical fixes. I don't get time to work on it as it is so don't want to create extra work for myself if don't need to. :-) |
I dont see how python 2.7 should be affected. The stub files will just be ignored by Python 2.7, so I dont see any problem with it. |
I was referring to a more robust typed solution targeting PY3+. |
Did you by chance get an opportunity to throw together a type hints file to get me started? Have started reading up on how they work but will take me some more time to work out what I need to provide the hints for. |
I will make a PR tomorrow, should be easy |
Dear Graham,
I have a simple decorator, which checks if Keywords are present -
It is a PEP561 Package, so type annotated - but I cant annotate for wrapt :
I tried a lot of different versions, but mypy doesnt stop to complain.
please help !
Robert
The text was updated successfully, but these errors were encountered: