-
-
Notifications
You must be signed in to change notification settings - Fork 372
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
Typing fails when list of validators where one is custom and one is built in #1197
Comments
It looks like Mypy type inference isn't strong enough. reveal_type([validators.max_len(10), is_not_empty]) # Revealed type is "builtins.list[builtins.function]" Funnily enough, if you hold its hand enough, it works: from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from attr import _ValidatorType
test: _ValidatorType = is_not_empty
reveal_type([validators.max_len(10), test]) # Revealed type is "builtins.list[def (Any, attr.Attribute[Any], Any) -> Any]" I couldn't figure out an elegant way of making it work. I'd suggest just sticking a |
I did consider importing the |
It wouldn't be the end of the world, but I wish we could come up with a better solution. |
Hi, just wanted to say that I'm running into the same issue, so: +1 |
I just noticed that this is not restricted to combinations of built-in and custom validators but also holds for lists of built-in validators. Both the following classes do the same job, but class
|
Hi!
I am trying to add multiple validators to a field, which works fine as long as they are both from the
attrs
library or both written by me. When I mix them up mypy gives me an error. Am I doing something wrong here or is this an issue in the library? Here is a snippet to reproduce the issue:This is the error I get from mypy:
The text was updated successfully, but these errors were encountered: