-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Default src.root to ['.', '<project_name>'] if the directory exists
#18141
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
Conversation
069d2bb to
7701d68
Compare
|
and mypy primer hangs here too :( I wonder if it is just because of the too large diff. Any suggestions on how I could try this out? |
|
6cfa747 to
74d5f25
Compare
There are no other changes to mypy primer, so maybe it's not worth changing the default just for one project. I'd be interested to hear from people with more knowledge of the Python ecosystem to hear how common this project structure is. |
|
I think we should fix this for this specific mypy primer project for now. We can consider changing our heuristics if this comes up more frequently. |
|
This proposed change makes a lot of sense to me. The I think we should also add |
|
I also wouldn't have any objection to resurrecting and landing this PR; it doesn't seem to have any downside. I'm not sure it's necessary that we check that |
Never mind this, Alex pointed out that if just |
I'm up for this but I suggest doing this in a separate PR. While related, it needs to apply to all layouts. |
|
sounds good |
…rals * origin/main: [ty] Add hint that PEP 604 union syntax is only available in 3.10+ (#18192) Unify `Message` variants (#18051) [`airflow`] Update `AIR301` and `AIR311` with the latest Airflow implementations (#17985) [`airflow`] Move rules from `AIR312` to `AIR302` (#17940) [ty] Small LSP cleanups (#18201) [ty] Show related information in diagnostic (#17359) Default `src.root` to `['.', '<project_name>']` if the directory exists (#18141)
* main: [ty] Use first matching constructor overload when inferring specializations (#18204) [ty] Add hint that PEP 604 union syntax is only available in 3.10+ (#18192) Unify `Message` variants (#18051) [`airflow`] Update `AIR301` and `AIR311` with the latest Airflow implementations (#17985) [`airflow`] Move rules from `AIR312` to `AIR302` (#17940) [ty] Small LSP cleanups (#18201) [ty] Show related information in diagnostic (#17359) Default `src.root` to `['.', '<project_name>']` if the directory exists (#18141)
Summary
I noticed in #18137 that we fail to resolve all imports for some ecosystem repositories because they don't use the "traditional" src or flat layouts. Instead, they use a
srclayout but they use the project name instead ofsrcfor the "src folder name".An example is
psycopgwhere all source files are inpsycopg/psycopg/_adapters_map.py:279:14This PR extends our heuristics for
src.rootto recognize if a project has a<project>/<project>folder (and nosrcfolder) and, if so, includes it in thesrc.root.The motivation for this change is to support more projects with zero configuration.
I don't have a good sense of how common this project layout is, but it seems worth supporting, given that multiple ecosystem projects use it. This also makes our mypy primer results significantely more useful :)
Test plan
See mypy primer results, added unit tests.