Skip to content

Commit cf7c263

Browse files
committed
fix tests
1 parent 16a9831 commit cf7c263

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

scripts/typecheck_tests.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,16 +500,12 @@
500500
'update',
501501
'update_only_fields',
502502
'urlpatterns',
503-
504503
# not annotatable without annotation in test
505504
# TODO: 'urlpatterns_reverse',
506-
507505
'user_commands',
508506
# TODO: 'utils_tests',
509-
510507
# not annotatable without annotation in test
511508
# TODO: 'validation',
512-
513509
'validators',
514510
'version',
515511
'view_tests',

test-data/typecheck/model_create.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class User(models.Model):
66
age = models.IntegerField()
77

88
User.objects.create(name='Max', age=10)
9-
User.objects.create(name=1010) # E: Incompatible type for "name" of "User" (got "int", expected "Union[str, Combinable]")
9+
User.objects.create(age='hello') # E: Incompatible type for "age" of "User" (got "str", expected "Union[int, Combinable, Literal['']]")
1010
[out]
1111

1212
[CASE model_recognises_parent_attributes]

test-data/typecheck/model_init.test

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ from django.db import models
1414
class MyUser(models.Model):
1515
name = models.CharField(max_length=100)
1616
age = models.IntegerField()
17-
user = MyUser(name=1, age=12)
17+
user = MyUser(name='hello', age='world')
1818
[out]
19-
main:6: error: Incompatible type for "name" of "MyUser" (got "int", expected "Union[str, Combinable]")
19+
main:6: error: Incompatible type for "age" of "MyUser" (got "str", expected "Union[int, Combinable, Literal['']]")
2020

2121
[CASE arguments_to_init_combined_from_base_classes]
2222
from django.db import models
@@ -62,8 +62,8 @@ user3= MyUser2(pk=1)
6262
from django.db import models
6363

6464
class MyUser1(models.Model):
65-
mypk = models.CharField(primary_key=True)
66-
user = MyUser1(pk=1) # E: Incompatible type for "pk" of "MyUser1" (got "int", expected "Union[str, Combinable]")
65+
mypk = models.IntegerField(primary_key=True)
66+
user = MyUser1(pk='hello') # E: Incompatible type for "pk" of "MyUser1" (got "str", expected "Union[int, Combinable, Literal['']]")
6767
[out]
6868

6969
[CASE can_set_foreign_key_by_its_primary_key]
@@ -72,13 +72,13 @@ from django.db import models
7272
class Publisher(models.Model):
7373
pass
7474
class PublisherWithCharPK(models.Model):
75-
id = models.CharField(max_length=100, primary_key=True)
75+
id = models.IntegerField(primary_key=True)
7676
class Book(models.Model):
7777
publisher = models.ForeignKey(Publisher, on_delete=models.CASCADE)
7878
publisher_with_char_pk = models.ForeignKey(PublisherWithCharPK, on_delete=models.CASCADE)
7979

80-
Book(publisher_id=1, publisher_with_char_pk_id='hello')
81-
Book(publisher_id=1, publisher_with_char_pk_id=1) # E: Incompatible type for "publisher_with_char_pk_id" of "Book" (got "int", expected "Union[str, Combinable]")
80+
Book(publisher_id=1, publisher_with_char_pk_id=1)
81+
Book(publisher_id=1, publisher_with_char_pk_id='hello') # E: Incompatible type for "publisher_with_char_pk_id" of "Book" (got "str", expected "Union[int, Combinable, Literal['']]")
8282
[out]
8383

8484
[CASE setting_value_to_an_array_of_ints]
@@ -112,9 +112,9 @@ class MyModel(models.Model):
112112
MyModel(1)
113113

114114
class MyModel2(models.Model):
115-
name = models.CharField(max_length=100)
116-
MyModel2(1, 'Maxim')
117-
MyModel2(1, 12) # E: Incompatible type for "name" of "MyModel2" (got "int", expected "Union[str, Combinable]")
115+
name = models.IntegerField()
116+
MyModel2(1, 12)
117+
MyModel2(1, 'Maxim') # E: Incompatible type for "name" of "MyModel2" (got "str", expected "Union[int, Combinable, Literal['']]")
118118
[out]
119119

120120
[CASE arguments_passed_as_dictionary_unpacking_are_not_supported]

0 commit comments

Comments
 (0)