Skip to content

Catch type error on django models #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ivanrvpereira opened this issue Mar 19, 2019 · 1 comment
Closed

Catch type error on django models #52

ivanrvpereira opened this issue Mar 19, 2019 · 1 comment

Comments

@ivanrvpereira
Copy link

ivanrvpereira commented Mar 19, 2019

It is possible to have type errors for django models?

class A(models.Model):
    pass

class B(models.Model):
    pass

def service(a: A) -> int:
    pass

a_instance = A()
b_instance = B()
service(b)  # no type error

It would help a lot if this could be caught earlier on the editor.
Because all models inherit from models.Model and

Every class is also a valid type. Any instance of a subclass is also compatible with all superclasses

I' m trying to figure if there is an option to detect this errors.

syastrov added a commit to syastrov/django-stubs that referenced this issue Mar 23, 2019
@syastrov
Copy link
Contributor

Looks like a bug caused by setting fallback_to_any to True on the Model type in the plugin.
I will make a PR with a fix.

syastrov added a commit to syastrov/django-stubs that referenced this issue Mar 28, 2019
…h other due to fallback_to_any = True. Fixes typeddjango#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.
syastrov added a commit to syastrov/django-stubs that referenced this issue Mar 28, 2019
…h other due to fallback_to_any = True. Fixes typeddjango#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants