Skip to content
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

Fixup db.models.fields.Field overloads for pyright 1.1.378 #265

Merged
merged 6 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion django-stubs/contrib/admin/templatetags/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class InclusionAdminNode(InclusionNode):
args: list[Any]
func: Callable[..., Any]
kwargs: dict[Any, Any]
takes_context: bool
takes_context: bool # pyright: ignore[reportIncompatibleVariableOverride]
template_name: str = ...
def __init__(
self,
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/contenttypes/fields.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class GenericForeignKey(FieldCacheMixin):
def __set__(self, instance: Model, value: Any | None) -> None: ...

class GenericRel(ForeignObjectRel):
field: GenericRelation
field: GenericRelation # pyright: ignore[reportIncompatibleVariableOverride]
def __init__(
self,
field: GenericRelation,
Expand Down
4 changes: 3 additions & 1 deletion django-stubs/contrib/contenttypes/models.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class ContentType(models.Model):
id: int
app_label: models.CharField[Any] = ...
model: models.CharField[Any] = ...
objects: ClassVar[ContentTypeManager] = ...
objects: ClassVar[ # pyright: ignore[reportIncompatibleVariableOverride]
ContentTypeManager
] = ...
permission_set: Manager[Permission]
@property
def name(self) -> str: ...
Expand Down
8 changes: 5 additions & 3 deletions django-stubs/contrib/postgres/fields/array.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ class ArrayField(CheckFieldDefaultMixin, Generic[_V], Field[_V | Combinable, _V]
from_db_value: Any = ...
base_field: Field[_V, _V] = ...
@overload
def __new__( # type: ignore [misc]
def __new__(
cls,
base_field: Field[Any, _V],
size: int | None = ...,
verbose_name: str | None = ...,
*,
name: str | None = ...,
primary_key: bool = ...,
max_length: int | None = ...,
unique: bool = ...,
blank: bool = ...,
null: Literal[False] = ...,
null: Literal[False] = False,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still want these to be ..., I think in general type stubs don't specify the actual default value

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if i understood it correctly, then we can't do ... more. We definitely need a default value, for the correct choice of @overload. microsoft/pyright#8860 was closed as "as designed", so i think stubs should accept this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed a bug that results in a false negative when overloads overlap due to default values.

pyright 1.1.378 changelog

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still want these to be ..., I think in general type stubs don't specify the actual default value

@sbdchd
How strong is your commitment to ...? Did the new rules in pyright introduce a bit of doubt?

The dev version of pylance already includes the new pyright, in a month it will appear for all users.

After which nullable fields will "break" in their projects, let's fix them in advance.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah seems like things have changed to allowing default values in stubs:
python/typeshed#8988 (comment)

keeping them in should be all good!

db_index: bool = ...,
default: list[_V] | Callable[[], list[_V]] | None = ...,
editable: bool = ...,
Expand All @@ -51,12 +52,13 @@ class ArrayField(CheckFieldDefaultMixin, Generic[_V], Field[_V | Combinable, _V]
base_field: Field[Any, _V],
size: int | None = ...,
verbose_name: str | None = ...,
*,
name: str | None = ...,
primary_key: bool = ...,
max_length: int | None = ...,
unique: bool = ...,
blank: bool = ...,
null: Literal[True] = ...,
null: Literal[True],
db_index: bool = ...,
default: list[_V] | Callable[[], list[_V]] | None = ...,
editable: bool = ...,
Expand Down
18 changes: 12 additions & 6 deletions django-stubs/contrib/postgres/fields/citext.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ class CICharField(CIText, CharField[_C]):
def __init__(
self: CICharField[str],
verbose_name: str | bytes | None = ...,
*,
name: str | None = ...,
primary_key: bool = ...,
max_length: int | None = ...,
unique: bool = ...,
blank: bool = ...,
null: Literal[False] = ...,
null: Literal[False] = False,
db_index: bool = ...,
default: Any = ...,
editable: bool = ...,
Expand All @@ -45,12 +46,13 @@ class CICharField(CIText, CharField[_C]):
def __init__(
self: CICharField[str | None],
verbose_name: str | bytes | None = ...,
*,
name: str | None = ...,
primary_key: bool = ...,
max_length: int | None = ...,
unique: bool = ...,
blank: bool = ...,
null: Literal[True] = ...,
null: Literal[True],
db_index: bool = ...,
default: Any = ...,
editable: bool = ...,
Expand All @@ -74,12 +76,13 @@ class CIEmailField(CIText, EmailField[_C]):
def __init__(
self: CIEmailField[str],
verbose_name: str | bytes | None = ...,
*,
name: str | None = ...,
primary_key: bool = ...,
max_length: int | None = ...,
unique: bool = ...,
blank: bool = ...,
null: Literal[False] = ...,
null: Literal[False] = False,
db_index: bool = ...,
default: Any = ...,
editable: bool = ...,
Expand All @@ -99,12 +102,13 @@ class CIEmailField(CIText, EmailField[_C]):
def __init__(
self: CIEmailField[str | None],
verbose_name: str | bytes | None = ...,
*,
name: str | None = ...,
primary_key: bool = ...,
max_length: int | None = ...,
unique: bool = ...,
blank: bool = ...,
null: Literal[True] = ...,
null: Literal[True],
db_index: bool = ...,
default: Any = ...,
editable: bool = ...,
Expand All @@ -128,12 +132,13 @@ class CITextField(CIText, TextField[_C]):
def __init__(
self: CITextField[str],
verbose_name: str | bytes | None = ...,
*,
name: str | None = ...,
primary_key: bool = ...,
max_length: int | None = ...,
unique: bool = ...,
blank: bool = ...,
null: Literal[False] = ...,
null: Literal[False] = False,
db_index: bool = ...,
default: Any = ...,
editable: bool = ...,
Expand All @@ -153,12 +158,13 @@ class CITextField(CIText, TextField[_C]):
def __init__(
self: CITextField[str | None],
verbose_name: str | bytes | None = ...,
*,
name: str | None = ...,
primary_key: bool = ...,
max_length: int | None = ...,
unique: bool = ...,
blank: bool = ...,
null: Literal[True] = ...,
null: Literal[True],
db_index: bool = ...,
default: Any = ...,
editable: bool = ...,
Expand Down
6 changes: 4 additions & 2 deletions django-stubs/contrib/postgres/fields/hstore.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ class HStoreField(Generic[_T], CheckFieldDefaultMixin, Field[Any, Any]):
def __init__(
self: HStoreField[dict[str, str | None]],
verbose_name: str | bytes | None = ...,
*,
name: str | None = ...,
primary_key: bool = ...,
max_length: int | None = ...,
unique: bool = ...,
blank: bool = ...,
null: Literal[False] = ...,
null: Literal[False] = False,
db_index: bool = ...,
default: Any = ...,
editable: bool = ...,
Expand All @@ -44,12 +45,13 @@ class HStoreField(Generic[_T], CheckFieldDefaultMixin, Field[Any, Any]):
def __init__(
self: HStoreField[dict[str, str | None] | None],
verbose_name: str | bytes | None = ...,
*,
name: str | None = ...,
primary_key: bool = ...,
max_length: int | None = ...,
unique: bool = ...,
blank: bool = ...,
null: Literal[True] = ...,
null: Literal[True],
db_index: bool = ...,
default: Any = ...,
editable: bool = ...,
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/core/files/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class File(FileProxyMixin, IO[Any]):
def close(self) -> None: ...

class ContentFile(File):
file: StringIO
file: StringIO # pyright: ignore[reportIncompatibleVariableOverride]
size: Any = ...
def __init__(self, content: bytes | str, name: str | None = ...) -> None: ...
def write(self, data: str) -> int: ... # type: ignore[override]
Expand Down
12 changes: 6 additions & 6 deletions django-stubs/core/mail/message.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ class MIMEMixin: ...

class SafeMIMEMessage(MIMEMixin, MIMEMessage):
defects: list[Any]
epilogue: None
epilogue: None # pyright: ignore[reportIncompatibleVariableOverride]
policy: Policy # type: ignore [no-any-unimported]
preamble: None
preamble: None # pyright: ignore[reportIncompatibleVariableOverride]

class SafeMIMEText(MIMEMixin, MIMEText):
defects: list[Any]
epilogue: None
epilogue: None # pyright: ignore[reportIncompatibleVariableOverride]
policy: Policy # type: ignore [no-any-unimported]
preamble: None
preamble: None # pyright: ignore[reportIncompatibleVariableOverride]
encoding: str = ...
def __init__(
self, _text: str, _subtype: str = ..., _charset: str = ...
) -> None: ...

class SafeMIMEMultipart(MIMEMixin, MIMEMultipart):
defects: list[Any]
epilogue: None
epilogue: None # pyright: ignore[reportIncompatibleVariableOverride]
policy: Policy # type: ignore [no-any-unimported]
preamble: None
preamble: None # pyright: ignore[reportIncompatibleVariableOverride]
encoding: str = ...
def __init__(
self,
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/core/serializers/json.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class DjangoJSONEncoder(json.JSONEncoder):
allow_nan: bool
check_circular: bool
ensure_ascii: bool
indent: int
indent: int # pyright: ignore[reportIncompatibleVariableOverride]
skipkeys: bool
sort_keys: bool
4 changes: 2 additions & 2 deletions django-stubs/core/servers/basehttp.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class WSGIRequestHandler(simple_server.WSGIRequestHandler):
close_connection: bool
connection: WSGIRequest
request: WSGIRequest
rfile: BytesIO
wfile: BytesIO
rfile: BytesIO # pyright: ignore[reportIncompatibleVariableOverride]
wfile: BytesIO # pyright: ignore[reportIncompatibleVariableOverride]
protocol_version: str = ...
def address_string(self) -> str: ...
def log_message(self, format: str, *args: Any) -> None: ...
Expand Down
Loading
Loading