Skip to content

Type inference fails for foreign keys with custom app names #51

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
aleksanb opened this issue Mar 19, 2019 · 0 comments · Fixed by #109
Closed

Type inference fails for foreign keys with custom app names #51

aleksanb opened this issue Mar 19, 2019 · 0 comments · Fixed by #109

Comments

@aleksanb
Copy link
Contributor

If you have a foreign key or similar that refers to a model with a string, and you have a custom app name for the app where that model lives, the inferred type falls back to Any:

class UserConfig(AppConfig):
    name = 'hyre.user'
    label = 'hyre__user'

if TYPE_CHECKING:
    from hyre.user.models import User

class MyClass(models.Model):
    some_fk = models.ForeignKey( 'hyre__user.User', ...)

mypy-django will look for the model User in a file called hyre__user, but only hyre.user exists in all_modules in helpers.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant