-
Notifications
You must be signed in to change notification settings - Fork 215
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
Type checker reports error when using the Use
class in a boolean operator
#322
Comments
I am not able to reproduce your issue. Is |
Mypy does not complain in that minimal example (even when in strict mode), but does complain when moving And(str, Use(str.lower), lambda s: s in ('alice', 'bob'))
# Mypy reports: Argument 2 to "And" has incompatible type "Use"; expected "Callable[..., Any]"
# VS Code (pyright) reports: The type 'Use' is incompatible with the types 'Schema' and '(...) -> Any'
# PyCharm reports something similar to VS Code
{'party': And(str, Use(str.lower), lambda s: s in ('alice', 'bob'))}
# Mypy still complains
Schema({'party': And(str, Use(str.lower), lambda s: s in ('alice', 'bob'))})
# Mypy does not report anything I haven't used Mypy before, so I'm not sure if it is a bug. I'm using schema 0.7.7 on Python 3.12. Mypy's version 1.11.1. |
ok, I now have the same issue. No solution yet but as a dirty workaround you can replace Use(str.lower) with eval("Use(str.lower)") |
That's really ugly. Why not just ignore the error?
|
@mutricyl By the way, not to criticize, but I noticed your markdown code snippet looks like this (copy and pasted from your comment): > ```python
> print("Hello World!")
> ``` Those greater than symbols are unnecessary. Just typing ``` is sufficient: ```python
print("Hello World!")
``` Hope this helps! |
Understood, thank you. Now I've put all schemas in a single file, so I can just disable type checking for that file. I'm comfortable with this. |
I agree that the Apparently mypy does not consider class Use:
(...)
def __call__(self, *args: Any, **kwds: Any) -> Any:
pass However I still have an issue mixing |
Here is a minimal example:
This code works fine. However, the type checker reports an error saying that a
Use
instance cannot be used as an argument ofAnd()
. This is true in both VS Code (which uses pyright by default) and PyCharm.I'm using similar validation rules in many places. As a result, my code is full of
# type: ignore
s because otherwise I will have to disable type checking completely.Is it possible to solve this issue?
The text was updated successfully, but these errors were encountered: