diff --git a/django-stubs/core/paginator.pyi b/django-stubs/core/paginator.pyi index b0da16dbf..147a117e3 100644 --- a/django-stubs/core/paginator.pyi +++ b/django-stubs/core/paginator.pyi @@ -31,8 +31,8 @@ class Paginator(Generic[_T]): allow_empty_first_page: bool = ..., ) -> None: ... def __iter__(self) -> Iterator[Page[_T]]: ... - def validate_number(self, number: float | str) -> int: ... - def get_page(self, number: float | str | None) -> Page[_T]: ... + def validate_number(self, number: int | float | str) -> int: ... + def get_page(self, number: int | float | str | None) -> Page[_T]: ... def page(self, number: int | str) -> Page[_T]: ... @property def count(self) -> int: ... @@ -41,7 +41,7 @@ class Paginator(Generic[_T]): @property def page_range(self) -> range: ... def get_elided_page_range( - self, number: float | str = ..., *, on_each_side: int = ..., on_ends: int = ... + self, number: int | float | str = ..., *, on_each_side: int = ..., on_ends: int = ... ) -> Iterator[str | int]: ... QuerySetPaginator: TypeAlias = Paginator diff --git a/django-stubs/db/models/fields/__init__.pyi b/django-stubs/db/models/fields/__init__.pyi index 9cebd0e38..64567d248 100644 --- a/django-stubs/db/models/fields/__init__.pyi +++ b/django-stubs/db/models/fields/__init__.pyi @@ -221,7 +221,7 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]): def value_to_string(self, obj: Model) -> str: ... class IntegerField(Field[_ST, _GT]): - _pyi_private_set_type: float | str | Combinable + _pyi_private_set_type: float | int | str | Combinable _pyi_private_get_type: int _pyi_lookup_exact_type: str | int @@ -235,7 +235,7 @@ class SmallIntegerField(IntegerField[_ST, _GT]): ... class BigIntegerField(IntegerField[_ST, _GT]): ... class FloatField(Field[_ST, _GT]): - _pyi_private_set_type: float | str | Combinable + _pyi_private_set_type: float | int | str | Combinable _pyi_private_get_type: float _pyi_lookup_exact_type: float diff --git a/django-stubs/db/models/lookups.pyi b/django-stubs/db/models/lookups.pyi index e9d3429b5..25a82aa43 100644 --- a/django-stubs/db/models/lookups.pyi +++ b/django-stubs/db/models/lookups.pyi @@ -83,8 +83,8 @@ class IntegerFieldFloatRounding: rhs: Any def get_prep_lookup(self) -> Any: ... -class IntegerGreaterThanOrEqual(IntegerFieldFloatRounding, GreaterThanOrEqual[float]): ... -class IntegerLessThan(IntegerFieldFloatRounding, LessThan[float]): ... +class IntegerGreaterThanOrEqual(IntegerFieldFloatRounding, GreaterThanOrEqual[int | float]): ... +class IntegerLessThan(IntegerFieldFloatRounding, LessThan[int | float]): ... class In(FieldGetDbPrepValueIterableMixin, BuiltinLookup): def split_parameter_list_as_sql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper) -> Any: ... diff --git a/django-stubs/forms/fields.pyi b/django-stubs/forms/fields.pyi index b49e95690..aec81189f 100644 --- a/django-stubs/forms/fields.pyi +++ b/django-stubs/forms/fields.pyi @@ -122,8 +122,8 @@ class FloatField(IntegerField): def __init__( self, *, - max_value: float | None = ..., - min_value: float | None = ..., + max_value: int | float | None = ..., + min_value: int | float | None = ..., required: bool = ..., widget: Widget | type[Widget] | None = ..., label: _StrOrPromise | None = ..., @@ -146,8 +146,8 @@ class DecimalField(IntegerField): def __init__( self, *, - max_value: Decimal | float | None = ..., - min_value: Decimal | float | None = ..., + max_value: Decimal | int | float | None = ..., + min_value: Decimal | int | float | None = ..., max_digits: int | None = ..., decimal_places: int | None = ..., required: bool = ..., diff --git a/django-stubs/template/defaultfilters.pyi b/django-stubs/template/defaultfilters.pyi index b035a2af0..d0a29e474 100644 --- a/django-stubs/template/defaultfilters.pyi +++ b/django-stubs/template/defaultfilters.pyi @@ -63,7 +63,7 @@ def default(value: int | str | None, arg: int | str) -> int | str: ... def default_if_none(value: str | None, arg: int | str) -> int | str: ... def divisibleby(value: int, arg: int) -> bool: ... def yesno(value: int | None, arg: str | None = ...) -> bool | str | None: ... -def filesizeformat(bytes_: complex | str) -> str: ... +def filesizeformat(bytes_: complex | int | str) -> str: ... def pluralize(value: Any, arg: str = ...) -> str: ... def phone2numeric_filter(value: str) -> str: ... def pprint(value: Any) -> str: ... diff --git a/django-stubs/test/testcases.pyi b/django-stubs/test/testcases.pyi index 54642e695..ced8d84b3 100644 --- a/django-stubs/test/testcases.pyi +++ b/django-stubs/test/testcases.pyi @@ -167,13 +167,13 @@ class SimpleTestCase(unittest.TestCase): def assertJSONEqual( self, raw: str, - expected_data: dict[str, Any] | list[Any] | str | float | bool | None, + expected_data: dict[str, Any] | list[Any] | str | int | float | bool | None, msg: str | None = ..., ) -> None: ... def assertJSONNotEqual( self, raw: str, - expected_data: dict[str, Any] | list[Any] | str | float | bool | None, + expected_data: dict[str, Any] | list[Any] | str | int | float | bool | None, msg: str | None = ..., ) -> None: ... def assertXMLEqual(self, xml1: str, xml2: str, msg: str | None = ...) -> None: ... diff --git a/setup.cfg b/setup.cfg index 1441ce65e..46993537c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,7 +3,7 @@ exclude = .*/ extend-ignore = E203 max_line_length = 120 per-file-ignores = - *.pyi: B, E301, E302, E305, E501, E701, E741, E743, NQA102, F401, F403, F405, F822, Y021, Y024, Y043 + *.pyi: B, E301, E302, E305, E501, E701, E741, E743, NQA102, F401, F403, F405, F822, Y021, Y024, Y041, Y043 [metadata] license_file = LICENSE.txt diff --git a/tests/typecheck/fields/test_related.yml b/tests/typecheck/fields/test_related.yml index e66f35ff0..18921e2f8 100644 --- a/tests/typecheck/fields/test_related.yml +++ b/tests/typecheck/fields/test_related.yml @@ -387,9 +387,9 @@ reveal_type(Book2().publisher_id) # N: Revealed type is "builtins.int" Book2(publisher_id=1) - Book2(publisher_id=[]) # E: Incompatible type for "publisher_id" of "Book2" (got "List[Any]", expected "Union[float, str, Combinable]") + Book2(publisher_id=[]) # E: Incompatible type for "publisher_id" of "Book2" (got "List[Any]", expected "Union[float, int, str, Combinable]") Book2.objects.create(publisher_id=1) - Book2.objects.create(publisher_id=[]) # E: Incompatible type for "publisher_id" of "Book2" (got "List[Any]", expected "Union[float, str, Combinable]") + Book2.objects.create(publisher_id=[]) # E: Incompatible type for "publisher_id" of "Book2" (got "List[Any]", expected "Union[float, int, str, Combinable]") installed_apps: - myapp files: diff --git a/tests/typecheck/models/test_create.yml b/tests/typecheck/models/test_create.yml index aaea40a4c..e82ff7be4 100644 --- a/tests/typecheck/models/test_create.yml +++ b/tests/typecheck/models/test_create.yml @@ -2,7 +2,7 @@ main: | from myapp.models import User User.objects.create(pk=1, name='Max', age=10) - User.objects.create(age=[]) # E: Incompatible type for "age" of "User" (got "List[Any]", expected "Union[float, str, Combinable]") + User.objects.create(age=[]) # E: Incompatible type for "age" of "User" (got "List[Any]", expected "Union[float, int, str, Combinable]") installed_apps: - myapp files: @@ -62,7 +62,7 @@ main: | from myapp.models import Publisher, Book - Book.objects.create(id=None) # E: Incompatible type for "id" of "Book" (got "None", expected "Union[float, str, Combinable]") + Book.objects.create(id=None) # E: Incompatible type for "id" of "Book" (got "None", expected "Union[float, int, str, Combinable]") Book.objects.create(publisher=None) # E: Incompatible type for "publisher" of "Book" (got "None", expected "Union[Publisher, Combinable]") Book.objects.create(publisher_id=None) # E: Incompatible type for "publisher_id" of "Book" (got "None", expected "Union[Combinable, int, str]") installed_apps: @@ -104,18 +104,18 @@ reveal_type(first.id) # N: Revealed type is "builtins.int" from myapp.models import MyModel2 - MyModel2(id=None) # E: Incompatible type for "id" of "MyModel2" (got "None", expected "Union[float, str, Combinable]") - MyModel2.objects.create(id=None) # E: Incompatible type for "id" of "MyModel2" (got "None", expected "Union[float, str, Combinable]") + MyModel2(id=None) # E: Incompatible type for "id" of "MyModel2" (got "None", expected "Union[float, int, str, Combinable]") + MyModel2.objects.create(id=None) # E: Incompatible type for "id" of "MyModel2" (got "None", expected "Union[float, int, str, Combinable]") second = MyModel2() - second.id = None # E: Incompatible types in assignment (expression has type "None", variable has type "Union[float, str, Combinable]") + second.id = None # E: Incompatible types in assignment (expression has type "None", variable has type "Union[float, int, str, Combinable]") reveal_type(second.id) # N: Revealed type is "builtins.int" # default set but no primary key doesn't allow None from myapp.models import MyModel3 - MyModel3(default=None) # E: Incompatible type for "default" of "MyModel3" (got "None", expected "Union[float, str, Combinable]") - MyModel3.objects.create(default=None) # E: Incompatible type for "default" of "MyModel3" (got "None", expected "Union[float, str, Combinable]") + MyModel3(default=None) # E: Incompatible type for "default" of "MyModel3" (got "None", expected "Union[float, int, str, Combinable]") + MyModel3.objects.create(default=None) # E: Incompatible type for "default" of "MyModel3" (got "None", expected "Union[float, int, str, Combinable]") third = MyModel3() - third.default = None # E: Incompatible types in assignment (expression has type "None", variable has type "Union[float, str, Combinable]") + third.default = None # E: Incompatible types in assignment (expression has type "None", variable has type "Union[float, int, str, Combinable]") reveal_type(third.default) # N: Revealed type is "builtins.int" installed_apps: - myapp diff --git a/tests/typecheck/models/test_init.yml b/tests/typecheck/models/test_init.yml index 107f8c061..ebc100671 100644 --- a/tests/typecheck/models/test_init.yml +++ b/tests/typecheck/models/test_init.yml @@ -37,7 +37,7 @@ from myapp.models import MyUser user = MyUser(name='hello', age=[]) out: | - main:2: error: Incompatible type for "age" of "MyUser" (got "List[Any]", expected "Union[float, str, Combinable]") + main:2: error: Incompatible type for "age" of "MyUser" (got "List[Any]", expected "Union[float, int, str, Combinable]") installed_apps: - myapp files: @@ -107,7 +107,7 @@ - case: typechecking_of_pk main: | from myapp.models import MyUser1 - user = MyUser1(pk=[]) # E: Incompatible type for "pk" of "MyUser1" (got "List[Any]", expected "Union[float, str, Combinable, None]") + user = MyUser1(pk=[]) # E: Incompatible type for "pk" of "MyUser1" (got "List[Any]", expected "Union[float, int, str, Combinable, None]") installed_apps: - myapp files: @@ -155,11 +155,11 @@ class NotAValid: pass array_val3: List[NotAValid] = [NotAValid()] - MyModel(array=array_val3) # E: Incompatible type for "array" of "MyModel" (got "List[NotAValid]", expected "Union[Sequence[Union[float, str]], Combinable]") + MyModel(array=array_val3) # E: Incompatible type for "array" of "MyModel" (got "List[NotAValid]", expected "Union[Sequence[Union[float, int, str]], Combinable]") non_init = MyModel() non_init.array = array_val non_init.array = array_val2 - non_init.array = array_val3 # E: Incompatible types in assignment (expression has type "List[NotAValid]", variable has type "Union[Sequence[Union[float, str]], Combinable]") + non_init.array = array_val3 # E: Incompatible types in assignment (expression has type "List[NotAValid]", variable has type "Union[Sequence[Union[float, int, str]], Combinable]") installed_apps: - myapp files: @@ -191,7 +191,7 @@ from myapp.models import MyModel, MyModel2 MyModel(1) MyModel2(1, 12) - MyModel2(1, []) # E: Incompatible type for "name" of "MyModel2" (got "List[Any]", expected "Union[float, str, Combinable]") + MyModel2(1, []) # E: Incompatible type for "name" of "MyModel2" (got "List[Any]", expected "Union[float, int, str, Combinable]") installed_apps: - myapp files: @@ -291,11 +291,11 @@ main:9: error: Incompatible types in assignment (expression has type "str", variable has type "int") main:10: error: Incompatible types in assignment (expression has type "str", variable has type "Union[int, float]") main:12: error: Incompatible types in assignment (expression has type "List[str]", variable has type "Sequence[Union[int, float]]") - main:13: error: Incompatible types in assignment (expression has type "List[]", variable has type "Union[float, str, Combinable]") + main:13: error: Incompatible types in assignment (expression has type "List[]", variable has type "Union[float, int, str, Combinable]") main:15: error: Incompatible type for "redefined_set_type" of "MyModel" (got "str", expected "int") main:15: error: Incompatible type for "redefined_union_set_type" of "MyModel" (got "str", expected "Union[int, float]") main:15: error: Incompatible type for "redefined_array_set_type" of "MyModel" (got "int", expected "Sequence[Union[int, float]]") - main:15: error: Incompatible type for "default_set_type" of "MyModel" (got "List[Any]", expected "Union[float, str, Combinable]") + main:15: error: Incompatible type for "default_set_type" of "MyModel" (got "List[Any]", expected "Union[float, int, str, Combinable]") installed_apps: - myapp files: