Skip to content

Conversation

@Gankra
Copy link
Contributor

@Gankra Gankra commented Dec 5, 2025

And try every possible desperate search-path instead of just the closest one.

The benefit here is that in 99.9% of cases we will have one less search-path, and we won't think things in the tests dir are available to the package itself.

@Gankra Gankra added ty Multi-file analysis & type inference ecosystem-analyzer labels Dec 5, 2025
@astral-sh-bot
Copy link

astral-sh-bot bot commented Dec 5, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@astral-sh-bot
Copy link

astral-sh-bot bot commented Dec 5, 2025

mypy_primer results

Changes were detected when running on open source projects
beartype (https://github.com/beartype/beartype)
+ beartype/claw/_package/clawpkgtrie.py:66:29: warning[unsupported-base] Unsupported class base with type `<class 'dict[str, PackagesTrieBlacklist]'> | <class 'dict[str, Divergent]'>`
+ beartype/claw/_package/clawpkgtrie.py:247:29: warning[unsupported-base] Unsupported class base with type `<class 'dict[str, PackagesTrieWhitelist]'> | <class 'dict[str, Divergent]'>`
- Found 492 diagnostics
+ Found 494 diagnostics

prefect (https://github.com/PrefectHQ/prefect)
- src/integrations/prefect-azure/tests/test_credentials.py:5:6: error[unresolved-import] Cannot resolve imported module `conftest`
- Found 5483 diagnostics
+ Found 5482 diagnostics

pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ pandas-stubs/_typing.pyi:1217:16: warning[unused-ignore-comment] Unused blanket `type: ignore` directive
- Found 5517 diagnostics
+ Found 5518 diagnostics

manticore (https://github.com/trailofbits/manticore)
+ server/tests/test_ethereum.py:16:6: error[unresolved-import] Cannot resolve imported module `tests.mock_classes`
+ server/tests/test_native.py:14:6: error[unresolved-import] Cannot resolve imported module `tests.mock_classes`
- Found 11070 diagnostics
+ Found 11072 diagnostics

No memory usage changes detected ✅

@Gankra Gankra changed the title [ty] don't add tests folders as roots [ty] move pytest search-path handling to desperate resolution Dec 5, 2025
@Gankra Gankra changed the title [ty] move pytest search-path handling to desperate resolution [ty] Move pytest search-path handling to desperate resolution Dec 5, 2025
@Gankra
Copy link
Contributor Author

Gankra commented Dec 5, 2025

Hmm this is tricky with the tests we have written, I need to look into what pytest actually does/supports.

@Gankra
Copy link
Contributor Author

Gankra commented Dec 5, 2025

Can't believe Carl convinced me randomly including tests with or without tests/__init__.py was arbitrary paranoia and not me having dark foresight of the nature of imports.

@astral-sh-bot
Copy link

astral-sh-bot bot commented Dec 5, 2025

ecosystem-analyzer results

Lint rule Added Removed Changed
unresolved-import 2 1 0
unsupported-base 2 1 0
unused-ignore-comment 0 2 0
Total 4 4 0

Full report with detailed diff (timing results)

@Gankra
Copy link
Contributor Author

Gankra commented Dec 5, 2025

Notably having multiple desperate search-paths is problematic for resolving relative imports, with our two-phases file_to_module and then resolve_module system. If . resolves to thismod then file_to_module succeeds but .sibling is syntactically invalid (only sibling works).

@Gankra
Copy link
Contributor Author

Gankra commented Dec 5, 2025

One kind of hacky solution would be to refuse to consider the dir the file is in a desperate search-path in file_to_module as we are typically resolving a relative import and so "this is a root module" is not helpful.

@Gankra
Copy link
Contributor Author

Gankra commented Dec 5, 2025

Tears of joy at how good these docs are omg https://docs.pytest.org/en/stable/explanation/pythonpath.html

@Gankra
Copy link
Contributor Author

Gankra commented Dec 5, 2025

One kind of hacky solution would be to refuse to consider the dir the file is in a desperate search-path in file_to_module as we are typically resolving a relative import and so "this is a root module" is not helpful.

The same can be accomplished by reversing the priority of the desperate search-paths: try the farthest ancestor dir first, allowing us to resolve . as the longest-possible-absolute path that is still valid.

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

Labels

ecosystem-analyzer ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove tests from the environment.root default

2 participants