Skip to content

Commit

Permalink
Upgrade to mypy 1.7.0 (#1837)
Browse files Browse the repository at this point in the history
  • Loading branch information
intgr authored Nov 10, 2023
1 parent eda5787 commit febc04e
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 28 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ We rely on different `django` and `mypy` versions:

| django-stubs | Mypy version | Django version | Django partial support | Python version |
|----------------|--------------|----------------|------------------------|----------------|
| (next version) | 1.7.x | 4.2 | 4.1, 3.2 | 3.8 - 3.12 |
| 4.2.6 | 1.6.x | 4.2 | 4.1, 3.2 | 3.8 - 3.12 |
| 4.2.5 | 1.6.x | 4.2 | 4.1, 3.2 | 3.8 - 3.12 |
| 4.2.4 | 1.5.x | 4.2 | 4.1, 3.2 | 3.8 - 3.11 |
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/admin/utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def lookup_field(
name: Callable | str, obj: Model, model_admin: BaseModelAdmin | None = ...
) -> tuple[Field | None, str | None, Any]: ...
@overload
def label_for_field( # type: ignore[misc]
def label_for_field( # type: ignore[overload-overlap]
name: Callable | str,
model: type[Model],
model_admin: BaseModelAdmin | None = ...,
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 @@ -9,7 +9,7 @@ from typing_extensions import Self
class File(FileProxyMixin[AnyStr], IO[AnyStr]):
DEFAULT_CHUNK_SIZE: int
file: IO[AnyStr] | None
name: str | None # type: ignore[assignment]
name: str | None
mode: str
def __init__(self, file: IO[AnyStr] | None, name: str | None = ...) -> None: ...
def __bool__(self) -> bool: ...
Expand Down
6 changes: 3 additions & 3 deletions django-stubs/db/backends/utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ class CursorDebugWrapper(CursorWrapper):
) -> Generator[None, None, None]: ...

@overload
def typecast_date(s: None | Literal[""]) -> None: ... # type: ignore[misc]
def typecast_date(s: None | Literal[""]) -> None: ... # type: ignore[overload-overlap]
@overload
def typecast_date(s: str) -> datetime.date: ...
@overload
def typecast_time(s: None | Literal[""]) -> None: ... # type: ignore[misc]
def typecast_time(s: None | Literal[""]) -> None: ... # type: ignore[overload-overlap]
@overload
def typecast_time(s: str) -> datetime.time: ...
@overload
def typecast_timestamp(s: None | Literal[""]) -> None: ... # type: ignore[misc]
def typecast_timestamp(s: None | Literal[""]) -> None: ... # type: ignore[overload-overlap]
@overload
def typecast_timestamp(s: str) -> datetime.datetime: ...
def split_identifier(identifier: str) -> tuple[str, str]: ...
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/db/models/sql/compiler.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ class SQLCompiler:
) -> Iterator[Sequence[Any]]: ...
def has_results(self) -> bool: ...
@overload
def execute_sql( # type: ignore[misc]
def execute_sql( # type: ignore[overload-overlap]
self, result_type: Literal["cursor"] = ..., chunked_fetch: bool = ..., chunk_size: int = ...
) -> CursorWrapper: ...
@overload
def execute_sql(
self, result_type: Literal["no results"] | None = ..., chunked_fetch: bool = ..., chunk_size: int = ...
) -> None: ...
@overload
def execute_sql( # type: ignore[misc]
def execute_sql( # type: ignore[overload-overlap]
self, result_type: Literal["single"] = ..., chunked_fetch: bool = ..., chunk_size: int = ...
) -> Iterable[Sequence[Any]] | None: ...
@overload
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/forms/models.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class ModelMultipleChoiceField(ModelChoiceField):

def modelform_defines_fields(form_class: type[ModelForm]) -> bool: ...
@overload
def _get_foreign_key( # type: ignore[misc]
def _get_foreign_key( # type: ignore[overload-overlap]
parent_model: type[Model], model: type[Model], fk_name: str | None = ..., can_fail: Literal[True] = ...
) -> ForeignKey | None: ...
@overload
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/template/response.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ContentNotRenderedError(Exception): ...
class SimpleTemplateResponse(HttpResponse):
content: Any
closed: bool
cookies: SimpleCookie[str]
cookies: SimpleCookie[str] # type: ignore[type-arg]
status_code: int
rendering_attrs: Any
template_name: _TemplateForResponseT
Expand Down Expand Up @@ -50,7 +50,7 @@ class TemplateResponse(SimpleTemplateResponse):
closed: bool
context: RequestContext
context_data: dict[str, Any] | None
cookies: SimpleCookie[str]
cookies: SimpleCookie[str] # type: ignore[type-arg]
csrf_cookie_set: bool
json: functools.partial
_request: HttpRequest
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/utils/encoding.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def iri_to_uri(iri: None) -> None: ...
@overload
def iri_to_uri(iri: str | Promise) -> str: ...
@overload
def uri_to_iri(uri: None) -> None: ... # type: ignore[misc]
def uri_to_iri(uri: None) -> None: ... # type: ignore[overload-overlap]
@overload
def uri_to_iri(uri: Any) -> str: ...
def escape_uri_path(path: str) -> str: ...
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/utils/formats.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ _T = TypeVar("_T")
# details it works as expected (all values from Union are `localize`d to str,
# while type of others is preserved)
@overload
def localize( # type: ignore[misc]
def localize( # type: ignore[overload-overlap]
value: builtin_datetime | date | time | Decimal | float | str, use_l10n: bool | None = ...
) -> str: ...
@overload
def localize(value: _T, use_l10n: bool | None = ...) -> _T: ...
@overload
def localize_input( # type: ignore[misc]
def localize_input( # type: ignore[overload-overlap]
value: builtin_datetime | date | time | Decimal | float | str, default: str | None = ...
) -> str: ...
@overload
Expand Down
3 changes: 2 additions & 1 deletion django-stubs/utils/xmlutils.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from xml.sax.saxutils import XMLGenerator
from xml.sax.xmlreader import AttributesImpl

class UnserializableContentError(ValueError): ...

class SimplerXMLGenerator(XMLGenerator):
def addQuickElement(self, name: str, contents: str | None = ..., attrs: dict[str, str] | None = ...) -> None: ...
def characters(self, content: str) -> None: ...
def startElement(self, name: str, attrs: dict[str, str]) -> None: ...
def startElement(self, name: str, attrs: AttributesImpl) -> None: ...
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Django==4.2.7
-e .[compatible-mypy]

# Overrides:
mypy==1.6.1
mypy==1.7.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def find_stub_files(name: str) -> List[str]:

# Keep compatible-mypy major.minor version pinned to what we use in CI (requirements.txt)
extras_require = {
"compatible-mypy": ["mypy~=1.6.0"],
"compatible-mypy": ["mypy~=1.7.0"],
}

setup(
Expand Down
2 changes: 1 addition & 1 deletion tests/typecheck/db/migrations/test_operations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
RunSQL(sql=["SOME SQLS", ("SOME SQLS %s, %s", [object(), "ANOTHER PARAM"])])
RunSQL(sql=("SOME SQL", {})) # E: Argument "sql" to "RunSQL" has incompatible type "Tuple[str, Dict[<nothing>, <nothing>]]"; expected "Union[str, Union[List[Union[str, Tuple[str, Union[Dict[str, Any], Union[List[Any], Tuple[Any, ...], Tuple[()]], None]]]], Tuple[Union[str, Tuple[str, Union[Dict[str, Any], Union[List[Any], Tuple[Any, ...], Tuple[()]], None]]], ...], Tuple[()]]]" [arg-type]
RunSQL(sql=("SOME SQL", {})) # E: Argument "sql" to "RunSQL" has incompatible type "Tuple[str, Dict[Never, Never]]"; expected "Union[str, Union[List[Union[str, Tuple[str, Union[Dict[str, Any], Union[List[Any], Tuple[Any, ...], Tuple[()]], None]]]], Tuple[Union[str, Tuple[str, Union[Dict[str, Any], Union[List[Any], Tuple[Any, ...], Tuple[()]], None]]], ...], Tuple[()]]]" [arg-type]
RunSQL(sql=("SOME SQL", 1)) # E: Argument "sql" to "RunSQL" has incompatible type "Tuple[str, int]"; expected "Union[str, Union[List[Union[str, Tuple[str, Union[Dict[str, Any], Union[List[Any], Tuple[Any, ...], Tuple[()]], None]]]], Tuple[Union[str, Tuple[str, Union[Dict[str, Any], Union[List[Any], Tuple[Any, ...], Tuple[()]], None]]], ...], Tuple[()]]]" [arg-type]
RunSQL(sql=("SOME SQL", None)) # E: Argument "sql" to "RunSQL" has incompatible type "Tuple[str, None]"; expected "Union[str, Union[List[Union[str, Tuple[str, Union[Dict[str, Any], Union[List[Any], Tuple[Any, ...], Tuple[()]], None]]]], Tuple[Union[str, Tuple[str, Union[Dict[str, Any], Union[List[Any], Tuple[Any, ...], Tuple[()]], None]]], ...], Tuple[()]]]" [arg-type]
RunSQL(sql=("SOME SQLS %(VAL)s", {1: "FOO"})) # E: Argument "sql" to "RunSQL" has incompatible type "Tuple[str, Dict[int, str]]"; expected "Union[str, Union[List[Union[str, Tuple[str, Union[Dict[str, Any], Union[List[Any], Tuple[Any, ...], Tuple[()]], None]]]], Tuple[Union[str, Tuple[str, Union[Dict[str, Any], Union[List[Any], Tuple[Any, ...], Tuple[()]], None]]], ...], Tuple[()]]]" [arg-type]
4 changes: 2 additions & 2 deletions tests/typecheck/fields/test_related.yml
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,8 @@
user = MyUser()
reveal_type(user.book_set) # N: Revealed type is "myapp.models.Book_RelatedManager"
reveal_type(user.article_set) # N: Revealed type is "myapp.models.Article_RelatedManager"
reveal_type(user.book_set.add) # N: Revealed type is "def (*objs: Union[myapp.models.Book, builtins.int], *, bulk: builtins.bool =)"
reveal_type(user.article_set.add) # N: Revealed type is "def (*objs: Union[myapp.models.Article, builtins.int], *, bulk: builtins.bool =)"
reveal_type(user.book_set.add) # N: Revealed type is "def (*objs: Union[myapp.models.Book, builtins.int], bulk: builtins.bool =)"
reveal_type(user.article_set.add) # N: Revealed type is "def (*objs: Union[myapp.models.Article, builtins.int], bulk: builtins.bool =)"
reveal_type(user.book_set.filter) # N: Revealed type is "def (*args: Any, **kwargs: Any) -> myapp.models.LibraryEntityQuerySet"
reveal_type(user.book_set.get()) # N: Revealed type is "myapp.models.Book"
reveal_type(user.article_set.filter) # N: Revealed type is "def (*args: Any, **kwargs: Any) -> myapp.models.LibraryEntityQuerySet"
Expand Down
16 changes: 8 additions & 8 deletions tests/typecheck/managers/querysets/test_from_queryset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
- case: from_queryset_returns_intersection_of_manager_and_queryset
main: |
from myapp.models import MyModel, NewManager
reveal_type(NewManager()) # N: Revealed type is "myapp.models.ModelBaseManagerFromModelQuerySet[<nothing>]"
reveal_type(NewManager()) # N: Revealed type is "myapp.models.ModelBaseManagerFromModelQuerySet[Never]"
reveal_type(MyModel.objects) # N: Revealed type is "myapp.models.ModelBaseManagerFromModelQuerySet[myapp.models.MyModel]"
reveal_type(MyModel.objects.get()) # N: Revealed type is "myapp.models.MyModel"
reveal_type(MyModel.objects.manager_only_method()) # N: Revealed type is "builtins.int"
Expand All @@ -283,12 +283,12 @@
- case: from_queryset_with_class_name_provided
main: |
from myapp.models import MyModel, NewManager, OtherModel, OtherManager
reveal_type(NewManager()) # N: Revealed type is "myapp.models.NewManager[<nothing>]"
reveal_type(NewManager()) # N: Revealed type is "myapp.models.NewManager[Never]"
reveal_type(MyModel.objects) # N: Revealed type is "myapp.models.NewManager[myapp.models.MyModel]"
reveal_type(MyModel.objects.get()) # N: Revealed type is "myapp.models.MyModel"
reveal_type(MyModel.objects.manager_only_method()) # N: Revealed type is "builtins.int"
reveal_type(MyModel.objects.manager_and_queryset_method()) # N: Revealed type is "builtins.str"
reveal_type(OtherManager()) # N: Revealed type is "myapp.models.X[<nothing>]"
reveal_type(OtherManager()) # N: Revealed type is "myapp.models.X[Never]"
reveal_type(OtherModel.objects) # N: Revealed type is "myapp.models.X[myapp.models.OtherModel]"
reveal_type(OtherModel.objects.manager_only_method()) # N: Revealed type is "builtins.int"
reveal_type(OtherModel.objects.manager_and_queryset_method()) # N: Revealed type is "builtins.str"
Expand Down Expand Up @@ -373,8 +373,8 @@
from myapp.models import MyModel
reveal_type(MyModel().objects) # N: Revealed type is "myapp.managers.ManagerFromModelQuerySet[myapp.models.MyModel]"
reveal_type(MyModel().objects.get()) # N: Revealed type is "myapp.models.MyModel"
reveal_type(MyModel().objects.base_queryset_method) # N: Revealed type is "def (param: Union[builtins.int, builtins.str]) -> <nothing>"
reveal_type(MyModel().objects.base_queryset_method(2)) # N: Revealed type is "<nothing>"
reveal_type(MyModel().objects.base_queryset_method) # N: Revealed type is "def (param: Union[builtins.int, builtins.str]) -> Never"
reveal_type(MyModel().objects.base_queryset_method(2)) # N: Revealed type is "Never"
installed_apps:
- myapp
files:
Expand Down Expand Up @@ -571,7 +571,7 @@
reveal_type(MyModel.objects.reverse) # N: Revealed type is "def () -> myapp.models.MyQuerySet[myapp.models.MyModel]"
reveal_type(MyModel.objects.select_for_update) # N: Revealed type is "def (nowait: builtins.bool =, skip_locked: builtins.bool =, of: typing.Sequence[builtins.str] =, no_key: builtins.bool =) -> myapp.models.MyQuerySet[myapp.models.MyModel]"
reveal_type(MyModel.objects.select_related) # N: Revealed type is "def (*fields: Any) -> myapp.models.MyQuerySet[myapp.models.MyModel]"
reveal_type(MyModel.objects.union) # N: Revealed type is "def (*other_qs: Any, *, all: builtins.bool =) -> myapp.models.MyQuerySet[myapp.models.MyModel]"
reveal_type(MyModel.objects.union) # N: Revealed type is "def (*other_qs: Any, all: builtins.bool =) -> myapp.models.MyQuerySet[myapp.models.MyModel]"
reveal_type(MyModel.objects.using) # N: Revealed type is "def (alias: Union[builtins.str, None]) -> myapp.models.MyQuerySet[myapp.models.MyModel]"
installed_apps:
- myapp
Expand Down Expand Up @@ -657,7 +657,7 @@
- case: handles_name_collision_with_generated_type
main: |
from myapp.models import MyModel, BaseManagerFromModelQuerySet
reveal_type(BaseManagerFromModelQuerySet()) # N: Revealed type is "myapp.models.BaseManagerFromModelQuerySet[<nothing>]"
reveal_type(BaseManagerFromModelQuerySet()) # N: Revealed type is "myapp.models.BaseManagerFromModelQuerySet[Never]"
reveal_type(MyModel.objects) # N: Revealed type is "myapp.models.BaseManagerFromModelQuerySet[myapp.models.MyModel]"
installed_apps:
- myapp
Expand All @@ -679,7 +679,7 @@
main: |
from myapp.models import MyModel, Generated, BaseManagerFromModelQuerySet
reveal_type(BaseManagerFromModelQuerySet) # N: Revealed type is "builtins.int"
reveal_type(Generated()) # N: Revealed type is "myapp.models.BaseManagerFromModelQuerySet1[<nothing>]"
reveal_type(Generated()) # N: Revealed type is "myapp.models.BaseManagerFromModelQuerySet1[Never]"
reveal_type(MyModel.objects) # N: Revealed type is "myapp.models.BaseManagerFromModelQuerySet1[myapp.models.MyModel]"
installed_apps:
- myapp
Expand Down
2 changes: 1 addition & 1 deletion tests/typecheck/models/test_init.yml
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
main:9: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment]
main:10: error: Incompatible types in assignment (expression has type "str", variable has type "Union[int, float]") [assignment]
main:12: error: Incompatible types in assignment (expression has type "List[str]", variable has type "Sequence[Union[int, float]]") [assignment]
main:13: error: Incompatible types in assignment (expression has type "List[<nothing>]", variable has type "Union[float, int, str, Combinable]") [assignment]
main:13: error: Incompatible types in assignment (expression has type "List[Never]", variable has type "Union[float, int, str, Combinable]") [assignment]
main:15: error: Incompatible type for "redefined_set_type" of "MyModel" (got "str", expected "int") [misc]
main:15: error: Incompatible type for "redefined_union_set_type" of "MyModel" (got "str", expected "Union[int, float]") [misc]
main:15: error: Incompatible type for "redefined_array_set_type" of "MyModel" (got "int", expected "Sequence[Union[int, float]]") [misc]
Expand Down

0 comments on commit febc04e

Please sign in to comment.