mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-08 04:54:48 +08:00
* Fix problem where Model instancess are not considered subtypes of each other due to fallback_to_any = True. Fixes #52. - Added a stub for __getstate__ to Model. - Added a stub for clean() to Model. - Correct arg type for sort_dependencies so they are covariant (Iterable rather than List). Test ignores: - Added some test ignores in cases where a model inherits from 2 different base models. - Added some test ignores for cases that MyPy flags as errors due to variable redefinitions or imports that are incompatible types. * Address review comment.
29 lines
589 B
Plaintext
29 lines
589 B
Plaintext
[CASE test_model_subtype_relationship_and_getting_and_setting_attributes]
|
|
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
|
|
|
|
a_instance = A()
|
|
b_instance = B()
|
|
reveal_type(b_instance.b_attr) # E: Revealed type is 'builtins.int'
|
|
|
|
|
|
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"
|
|
|
|
c_instance = C()
|
|
service(c_instance)
|