-
-
Notifications
You must be signed in to change notification settings - Fork 244
Type hint improvements #306
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: develop
Are you sure you want to change the base?
Conversation
The `P` and `T` ParamSpec and TypeVar attributes are bound and indicate the parameters of the *wrapper* function, not the *wrapped* function. Signed-off-by: Stephen Finucane <stephen@that.guru>
…er.__get__ Properly handle method binding by providing overrides that will strip the self/cls parameter when used on a method rather than a parameter. Tests are updated to reflect this improvement. Signed-off-by: Stephen Finucane <stephen@that.guru>
|
What is The type hints are the way they are because a more simplified approach doesn't work with various type checkers and results in various cases being flagged as problems when they aren't. Would also have been helpful to see how you are using type hints in your usage of |
|
I'm away without laptop this week so will have to follow up with a longer reply next week, but debtcollector is https://github.com/openstack/debtcollector and we're targeting mypy. I'm typing that as part of a larger effort to type various openstack libraries. If you look at |
|
Also, the fact that mypy at least is now able to correctly identify incorrect parameters and returns types rather than returning |
|
I can't find the TODO you reference. |
|
Apologies, it hasn't merged yet. https://review.opendev.org/c/openstack/debtcollector/+/972447 |
|
FWIW. For reference, prior type hint work on wrapt was based on testing against mypy 1.18.1. I see there is a 1.19 now. I don't know if that newer version addresses issues I see. From memory if plain Callable was used instead of complex overload I ended up using, mypy wouldn't work properly when wrapt decorators were applied to methods of a class, it just wouldn't handle self/cls argument properly and always complained was wrong number of arguments. |
|
I could also have that round the wrong way, and it is pyright that didn't work without the mess of overloads. So making if just Callable could well work for mypy on either version, but then pylance in VS Code will not work properly. So unfortunately compromises are needed since these static type checkers tools are not fool proof and still a work in progress. |
|
So some of the suggested changes for Am not sure that: is correct though in returning I also need to understand why you use: and why existing: were not appropriate. Still have big concerns over simplification of: As seems to happen quite often to me, not having using VS Code for a couple of months for this, its type checking features are totally broken for pylance and don't know why, so hard to test things right now with it. |
|
As usual, start tweaking stuff and other stuff just starts breaking. This is going to take a while to sort out as usual. 😩 |
|
I may have found a solution. Perhaps can use:
Can't have one of the argument alternatives (need to investigate implications of that on other things). The |
|
FWIW, the changes also seem to make some things work (different to |
|
But all of Only solution I can see right now is to extract a minimal self contained example of the problem and report issues against tools that cannot handle it. |

These were spotted while working on adding type hints to debtcollector. I believe the simplified types are correct, as evidenced by me no longer needing
type: ignorestatements in debtcollector plus the reduced failures in the tests, but this should definitely receive the twice-over.