Replies: 1 comment 2 replies
-
It's important to understand that pyright doesn't have any specific knowledge of Interestingly, if I switch your code to use the stdlib dataclass rather than attrs, both pyright and mypy detect that there's a mismatch in the default type. from dataclasses import dataclass, field
@dataclass
class Foo:
x: int = field(default=None) # Error: None is not assignable to int This error is detected because of the way that the def field(
*,
default: _T,
...
) -> _T: ... By contrast, @overload
def field(
*,
default: None = ...,
...
) -> Any: ... The return type for the call is evaluated as According to the So, I think pyright is working correctly here. Not surprisingly, mypy's behavior matches pyright's. Both pyright and mypy pass the type checker conformance tests for this functionality. |
Beta Was this translation helpful? Give feedback.
-
I ran into this seemingly inconsistent behaviour after incorrectly changing some attrs converters in agronholm/apscheduler#1014 (I forgot that the converters needed to account for a default value of
None
). However, pyright only errored whenAsyncScheduler
was used as an attrs factory. agronholm/apscheduler#1014 (comment) shows an example and the resulting error.Minimal repro:
My environment:
Beta Was this translation helpful? Give feedback.
All reactions