Skip to content

Commit

Permalink
revert changes done in #1253 that satisfy Y041, disable Y041 rule (#1256
Browse files Browse the repository at this point in the history
)

Signed-off-by: Oleg Hoefling <oleg.hoefling@ionos.com>

Signed-off-by: Oleg Hoefling <oleg.hoefling@ionos.com>
  • Loading branch information
hoefling committed Nov 15, 2022
1 parent 9a96178 commit a1c192c
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 32 deletions.
6 changes: 3 additions & 3 deletions django-stubs/core/paginator.pyi
Expand Up @@ -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: ...
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/db/models/fields/__init__.pyi
Expand Up @@ -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

Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions django-stubs/db/models/lookups.pyi
Expand Up @@ -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: ...
Expand Down
8 changes: 4 additions & 4 deletions django-stubs/forms/fields.pyi
Expand Up @@ -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 = ...,
Expand All @@ -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 = ...,
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/template/defaultfilters.pyi
Expand Up @@ -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: ...
4 changes: 2 additions & 2 deletions django-stubs/test/testcases.pyi
Expand Up @@ -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: ...
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -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
4 changes: 2 additions & 2 deletions tests/typecheck/fields/test_related.yml
Expand Up @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions tests/typecheck/models/test_create.yml
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions tests/typecheck/models/test_init.yml
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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[<nothing>]", variable has type "Union[float, str, Combinable]")
main:13: error: Incompatible types in assignment (expression has type "List[<nothing>]", 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:
Expand Down

0 comments on commit a1c192c

Please sign in to comment.