-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Incorrect @overload
overlaps detection with TypeVar(infer_variance=True)
#8860
Comments
The new behavior that you're seeing is correct. The reason you didn't see it previously was because of a bug in older versions of pyright. The problem here is that you have overlapping overloads that return incompatible types. If you were to call the You can fix the overlapping overload in your code by removing the |
The error also goes away if I swap the methods. @overload
def __new__(cls, null: Literal[True] = ...) -> Field[T_infer | None]: ...
@overload
def __new__(cls, null: Literal[False] = ...) -> Field[T_infer]: ... Unfortunately e.g.: def __new__( # type: ignore [misc]
cls,
verbose_name: str | None = ...,
name: str | None = ...,
auto_now: bool = ...,
auto_now_add: bool = ...,
primary_key: bool = ...,
max_length: int | None = ...,
unique: bool = ...,
blank: bool = ...,
null: Literal[False] = ...,
db_index: bool = ...,
default: _DT | Callable[[], _DT] | None = ...,
editable: bool = ...,
auto_created: bool = ...,
serialize: bool = ...,
unique_for_date: str | None = ...,
unique_for_month: str | None = ...,
unique_for_year: str | None = ...,
choices: Iterable[
tuple[_DT, str] | tuple[str, Iterable[tuple[_DT, str]]]
] = ...,
help_text: str = ...,
db_column: str | None = ...,
db_comment: str | None = ...,
db_tablespace: str | None = ...,
validators: Iterable[_ValidatorCallable] = ...,
error_messages: _ErrorMessagesToOverride | None = ...,
) -> DateTimeField[datetime]: ... For context: |
I found a solution, if you add def __new__(
cls,
*,
verbose_name: str | None = ...,
null: Literal[True],
): |
pyright 1.1.378
After upgrading from version 377,
pyright
found 1 error in my codebase, but I think it's a bug.If i add
infer_variance=True
toT
, the error will go away.The text was updated successfully, but these errors were encountered: