-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
False-positive errors for attrs - wrong types for default
argument?
#6207
Comments
Thanks, I'm able to repro the problem and will investigate further. Here's a simplified example that doesn't rely on attrs. from typing import Any, Callable, Generic, TypeVar
_T = TypeVar("_T")
class Attribute(Generic[_T]):
pass
_ValidatorType = Callable[[Any, Attribute[_T], _T], Any]
def field(*, default: _T, validator: _ValidatorType[_T]) -> _T:
...
def instance_of(type: type[_T]) -> _ValidatorType[_T]:
...
field(validator=instance_of(int), default=10) |
Just encountered a similar issue, but with from typing import Container, Generic, TypeVar, Callable, Any
_T = TypeVar("_T")
class Attribute(Generic[_T]): ...
_ValidatorType = Callable[[Any, Attribute[_T], _T], Any]
def field(default: _T, validator: _ValidatorType[_T]) -> _T: ...
def in_(options: Container[_T]) -> _ValidatorType[_T]: ...
s: list[str] = ["normal", "system"]
field("normal", in_(s))
|
…a generic function that involves a type variable used in both a covariant and contravariant (or invariant) position and both literal and non-literal types are involved. This addresses part of #6207.
I've fixed the bug associated with the original bug report. The other bug reported by @cdce8p is actually unrelated, so I've opened a separate issue (#8049) to track that one. The fix for the bug reported by @olivercoleman-switchdin will be included in the next release of pyright. |
This is addressed in pyright 1.1.366. |
Not sure if this belongs here, but I'm getting erroneous type errors for the
attrs
module.Field definitions like this:
Give errors like this:
Removing either the
validator
or thedefault
argument tofield
make the error go away.VS Code extension or command-line
I get the same error running PyRight in:
The text was updated successfully, but these errors were encountered: