-
-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make ignore_missing_model_attributes behaviour optional (#66)
make "ignore_missing_model_attributes" behaviour opt-in
- Loading branch information
Showing
7 changed files
with
64 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,60 @@ | ||
[CASE test_model_subtype_relationship_and_getting_and_setting_attributes] | ||
[CASE test_typechecking_for_model_subclasses] | ||
from django.db import models | ||
|
||
class A(models.Model): | ||
pass | ||
|
||
class B(models.Model): | ||
b_attr = 1 | ||
pass | ||
|
||
class C(A): | ||
pass | ||
|
||
def service(a: A) -> int: | ||
pass | ||
|
||
b_instance = B() | ||
service(b_instance) # E: Argument 1 to "service" has incompatible type "B"; expected "A" | ||
|
||
a_instance = A() | ||
c_instance = C() | ||
service(a_instance) | ||
service(c_instance) | ||
[/CASE] | ||
|
||
|
||
[CASE fail_if_no_such_attribute_on_model] | ||
from django.db import models | ||
|
||
class B(models.Model): | ||
b_attr = 1 | ||
pass | ||
|
||
b_instance = B() | ||
reveal_type(b_instance.b_attr) # E: Revealed type is 'builtins.int' | ||
|
||
reveal_type(b_instance.non_existent_attribute) | ||
b_instance.non_existent_attribute = 2 | ||
[out] | ||
main:10: error: Revealed type is 'Any' | ||
main:10: error: "B" has no attribute "non_existent_attribute" | ||
main:11: error: "B" has no attribute "non_existent_attribute" | ||
[/CASE] | ||
|
||
|
||
[CASE ignore_missing_attributes_if_setting_is_passed] | ||
from django.db import models | ||
|
||
class B(models.Model): | ||
pass | ||
|
||
b_instance = B() | ||
reveal_type(b_instance.non_existent_attribute) # E: Revealed type is 'Any' | ||
b_instance.non_existent_attribute = 2 | ||
|
||
service(b_instance) # E: Argument 1 to "service" has incompatible type "B"; expected "A" | ||
[env MYPY_DJANGO_CONFIG=${MYPY_CWD}/mypy_django.ini] | ||
|
||
c_instance = C() | ||
service(c_instance) | ||
[file mypy_django.ini] | ||
[[mypy_django_plugin] | ||
ignore_missing_model_attributes = True | ||
|
||
[/CASE] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters