fix integer set type

This commit is contained in:
Maxim Kurnikov
2019-02-20 02:38:39 +03:00
parent 78810f55b6
commit 5d8cdbcf29
10 changed files with 20 additions and 20 deletions

View File

@@ -5,7 +5,7 @@ by the DJANGO_SETTINGS_MODULE environment variable.
# This is defined here as a do-nothing function because we can't import
# django.utils.translation -- that module depends on the settings.
from typing import Any, Dict, List, Optional, Pattern, Tuple, Protocol, Union, Callable, TYPE_CHECKING
from typing import Any, Dict, List, Optional, Pattern, Tuple, Protocol, Union, Callable, TYPE_CHECKING, Sequence
####################
# CORE #
@@ -377,7 +377,7 @@ CACHE_MIDDLEWARE_ALIAS = "default"
AUTH_USER_MODEL: str = ...
AUTHENTICATION_BACKENDS: List[str] = ...
AUTHENTICATION_BACKENDS: Sequence[str] = ...
LOGIN_URL = "/accounts/login/"

View File

@@ -8,7 +8,6 @@ from django.core.exceptions import FieldDoesNotExist as FieldDoesNotExist
from django.db.models.expressions import Combinable
from django.db.models.query_utils import RegisterLookupMixin
from django.forms import Field as FormField, Widget
from typing_extensions import Literal
from .mixins import NOT_PROVIDED as NOT_PROVIDED
@@ -72,7 +71,7 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]):
def to_python(self, value: Any) -> Any: ...
class IntegerField(Field[_ST, _GT]):
_pyi_private_set_type: Union[int, Combinable, Literal[""]]
_pyi_private_set_type: Union[float, int, str, Combinable]
_pyi_private_get_type: int
class PositiveIntegerRelDbTypeMixin:

View File

@@ -246,7 +246,7 @@ def extract_primary_key_type_for_get(model: TypeInfo) -> Optional[Type]:
def make_optional(typ: Type):
return UnionType.make_simplified_union([typ, NoneTyp()])
return UnionType.make_union([typ, NoneTyp()])
def make_required(typ: Type) -> Type:

View File

@@ -55,8 +55,8 @@ def convert_any_to_type(typ: Type, referred_to_type: Type) -> Type:
converted_items = []
for item in typ.items:
converted_items.append(convert_any_to_type(item, referred_to_type))
return UnionType.make_simplified_union(converted_items,
line=typ.line, column=typ.column)
return UnionType.make_union(converted_items,
line=typ.line, column=typ.column)
if isinstance(typ, Instance):
args = []
for default_arg in typ.args:

View File

@@ -6,7 +6,7 @@ warn_no_return = False
show_traceback = True
warn_redundant_casts = True
allow_redefinition = True
incremental = True
incremental = False
plugins =
mypy_django_plugin.main

View File

@@ -286,7 +286,8 @@ IGNORED_ERRORS = {
],
'schema': [
'Incompatible type for "info" of "Note" (got "None", expected "Union[str, Combinable]")',
'Incompatible type for "detail_info" of "NoteRename" (got "None", expected "Union[str, Combinable]")'
'Incompatible type for "detail_info" of "NoteRename" (got "None", expected "Union[str, Combinable]")',
'Incompatible type for "year" of "UniqueTest" (got "None", expected "Union[float, int, str, Combinable]")'
],
'settings_tests': [
'Argument 1 to "Settings" has incompatible type "Optional[str]"; expected "str"'
@@ -348,7 +349,7 @@ IGNORED_ERRORS = {
],
'sessions_tests': [
'base class "SessionTestsMixin" defined the type as "None")',
'Incompatible types in assignment (expression has type "None", variable has type "int")'
'Incompatible types in assignment (expression has type "None", variable has type "int")',
],
'select_related_onetoone': [
'"None" has no attribute'

View File

@@ -6,7 +6,7 @@ class User(models.Model):
age = models.IntegerField()
User.objects.create(name='Max', age=10)
User.objects.create(age='hello') # E: Incompatible type for "age" of "User" (got "str", expected "Union[int, Combinable, Literal['']]")
User.objects.create(age=[]) # E: Incompatible type for "age" of "User" (got "List[Any]", expected "Union[float, int, str, Combinable]")
[out]
[CASE model_recognises_parent_attributes]
@@ -59,6 +59,6 @@ MyModel.objects.create(id=None)
class MyModel2(models.Model):
id = models.IntegerField(primary_key=True, default=None)
MyModel2(id=None) # E: Incompatible type for "id" of "MyModel2" (got "None", expected "Union[int, Combinable, Literal['']]")
MyModel2.objects.create(id=None) # E: Incompatible type for "id" of "MyModel2" (got "None", expected "Union[int, Combinable, Literal['']]")
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]")
[out]

View File

@@ -14,9 +14,9 @@ from django.db import models
class MyUser(models.Model):
name = models.CharField(max_length=100)
age = models.IntegerField()
user = MyUser(name='hello', age='world')
user = MyUser(name='hello', age=[])
[out]
main:6: error: Incompatible type for "age" of "MyUser" (got "str", expected "Union[int, Combinable, Literal['']]")
main:6: error: Incompatible type for "age" of "MyUser" (got "List[Any]", expected "Union[float, int, str, Combinable]")
[CASE arguments_to_init_combined_from_base_classes]
from django.db import models
@@ -63,7 +63,7 @@ from django.db import models
class MyUser1(models.Model):
mypk = models.IntegerField(primary_key=True)
user = MyUser1(pk='hello') # E: Incompatible type for "pk" of "MyUser1" (got "str", expected "Union[int, Combinable, Literal['']]")
user = MyUser1(pk=[]) # E: Incompatible type for "pk" of "MyUser1" (got "List[Any]", expected "Union[float, int, str, Combinable]")
[out]
[CASE can_set_foreign_key_by_its_primary_key]
@@ -115,7 +115,7 @@ MyModel(1)
class MyModel2(models.Model):
name = models.IntegerField()
MyModel2(1, 12)
MyModel2(1, 'Maxim') # E: Incompatible type for "name" of "MyModel2" (got "str", expected "Union[int, Combinable, Literal['']]")
MyModel2(1, []) # E: Incompatible type for "name" of "MyModel2" (got "List[Any]", expected "Union[float, int, str, Combinable]")
[out]
[CASE arguments_passed_as_dictionary_unpacking_are_not_supported]

View File

@@ -271,9 +271,9 @@ class Book2(models.Model):
reveal_type(Book2().publisher_id) # E: Revealed type is 'builtins.int'
Book2(publisher_id=1)
Book2(publisher_id='hello') # E: Incompatible type for "publisher_id" of "Book2" (got "str", expected "Union[int, Combinable, Literal[''], None]")
Book2(publisher_id=[]) # E: Incompatible type for "publisher_id" of "Book2" (got "List[Any]", expected "Union[float, int, str, Combinable, None]")
Book2.objects.create(publisher_id=1)
Book2.objects.create(publisher_id='hello') # E: Incompatible type for "publisher_id" of "Book2" (got "str", expected "Union[int, Combinable, Literal['']]")
Book2.objects.create(publisher_id=[]) # E: Incompatible type for "publisher_id" of "Book2" (got "List[Any]", expected "Union[float, int, str, Combinable]")
[out]
[CASE if_model_is_defined_as_name_of_the_class_look_for_it_in_the_same_file]

View File

@@ -41,7 +41,7 @@ ROOT_DIR = Path(__file__)
from django.conf import settings
reveal_type(settings.AUTH_USER_MODEL) # E: Revealed type is 'builtins.str'
reveal_type(settings.AUTHENTICATION_BACKENDS) # E: Revealed type is 'builtins.list[builtins.str]'
reveal_type(settings.AUTHENTICATION_BACKENDS) # E: Revealed type is 'typing.Sequence[builtins.str]'
[out]
[CASE test_circular_dependency_in_settings_works_if_settings_have_annotations]