-
-
Notifications
You must be signed in to change notification settings - Fork 459
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
Fix partially analyzed settings module #1162
Conversation
Signed-off-by: Anders Kaseorg <[email protected]>
For modules "django.http" and "django.http.request", we manually add dependency for the module containing "AUTH_USER_MODEL" for mypy to resolve first. This potentially adds cyclic dependency when the models module contains reference to django.conf, and the settings depend on any modules that rely on "django.http" or "django.http.request". At this point, the types of the settings are only partially resolved. Signed-off-by: Zixuan James Li <[email protected]>
That might not be a problem. My understanding is that a settings module is not supposed to have any dependencies on Django. That’s why |
Yes. Essentially the problem we want to solve here is the cyclic dependency that is not supposed to emerge from the settings. |
Hmm. Maybe my test case, and by extension the Zulip code it originated from, is just wrong for that reason. |
It is possible that this dependency is inevitable because it is from |
Maybe the application’s |
I ran this fix in Zulip. The error does not go away unless this |
I got it working by breaking a bunch of import cycles in Zulip (zulip/zulip#23040), and moving To make this solution robust, ideally we’d replace this fallback to |
This fallback to value.__class__ seems to be doing more harm than good; see typeddjango#312 and typeddjango#1162. Replace it with a clear error message that suggests a way to fix the problem rather than papering over it. Signed-off-by: Anders Kaseorg <[email protected]>
This fallback to value.__class__ seems to be doing more harm than good; see typeddjango#312 and typeddjango#1162. Replace it with a clear error message that suggests a way to fix the problem rather than incompletely papering over it. Signed-off-by: Anders Kaseorg <[email protected]>
This fallback to value.__class__ seems to be doing more harm than good; see typeddjango#312 and typeddjango#1162. Replace it with a clear error message that suggests a way to fix the problem rather than incompletely papering over it. Signed-off-by: Anders Kaseorg <[email protected]>
This fallback to value.__class__ seems to be doing more harm than good; see typeddjango#312 and typeddjango#1162. Replace it with a clear error message that suggests a way to fix the problem rather than incompletely papering over it. Signed-off-by: Anders Kaseorg <[email protected]>
This fallback to value.__class__ seems to be doing more harm than good; see #312 and #1162. Replace it with a clear error message that suggests a way to fix the problem rather than incompletely papering over it. Signed-off-by: Anders Kaseorg <[email protected]> Signed-off-by: Anders Kaseorg <[email protected]>
Instead we merged #1163 Thanks for working on this! |
I have made things!
For modules
django.http
anddjango.http.request
, we manually adddependency for the module containing
AUTH_USER_MODEL
for mypy toresolve first.
This potentially adds cyclic dependency when the models module contains
a reference to
django.conf
, and the settings depend on any modules thatrely on
django.http
ordjango.http.request
. At this point, the settings module isonly partially analyzed. The symbol table is populated (so top-level settings are
accessible by the name), but the types have not been inferred.
Removing this dependency of
django.http
anddjango.http.request
works. Butif the settings module also depends on
django.contrib.auth
, this still breaks.This can potentially break the refined type for
request.user
, which does dependon
AUTH_USER_MODEL
being available beforehand. This implicit dependencystill needs to be somehow established.
So, until these issues are addressed, this fix is not final.
Related issues