-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[ty] Move search path resolution to Options::to_program_settings
#18937
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
Options::to_program_settings
"Options::to_program_settings
|
|
if current_python_version != &python_version_from_environment | ||
&& current_python_version.source.priority() | ||
<= python_version_from_environment.source.priority() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if there's a test demonstrating why this is needed. The Default
, Config
and Cli
cases are inherent by how we resolve options. I would expect that the other cases work because we simply re-run the entire settings resolution (including the search path discovery) whenever the settings change and the priority should be encoded in the setting/search path resolution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I was possibly confused about when exactly the update_search_paths
method is called.
Could it be called without re-resolving all other settings if e.g. a .pth
file in the site-packages
directory changes (which affects editable-installation search paths)? If so, it's possible that the update_search_paths
method might accidentally override the Python version specified in a pyproject.toml file, even though the version in the pyproject.toml file should always take precedence over the Python version inferred from a virtual environment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's only called when the VERSIONS file in the typeshed directory changed and we then resolve all settings the same as we would when the configuration changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't checked line-by-line but the change makes sense to me, and nothing looked obviously wrong from skimming through. I also think we've got pretty good test coverage for all this, which gives me confidence in the refactor!
* main: [ty] Add regression-benchmark for attribute-assignment hang (#18957) [ty] Format conflicting types as an enumeration (#18956) [ty] Prevent union builder construction for just one declaration (#18954) [ty] Infer nonlocal types as unions of all reachable bindings (#18750) [`pyflakes`] Mark `F504`/`F522`/`F523` autofix as unsafe if there's a call with side effect (#18839) [`playground`] Add ruff logo docs link to Header.tsx (#18947) [ty] Reduce the overwhelming complexity of `TypeInferenceBuilder::infer_call_expression` (#18943) [ty] Add subdiagnostic about empty bodies in more cases (#18942) [ty] Move search path resolution to `Options::to_program_settings` (#18937) [`flake8-errmsg`] Extend `EM101` to support byte strings (#18867) Move big rule implementations (#18931) [`pylint`] Allow fix with comments and document performance implications (`PLW3301`) (#18936)
Summary
This PR moves the
SearchPaths::from_settings
call and the resolution of the final Python version intoOptions::to_program_settings
.We want to use
ProgramSettings
as a cache key for persistent caching (e.g., checking different Python versions should resolve in loading different persistent caches). For this to work well, it's important thatProgramSettings
mainly holds resolved settings. For example, it's essential that the following two runs in an activated virtual environment using Python 3.10 result in the same computed cache key:ty check --python-version 3.10
andty check
.The reason I made this change now is that I investigated what it would mean if the LSP passed the selected interpreter in the Python extension as a lowest-priority fallback value. We want to make sure that ty reuses the persistent cache between a
ty check --python-version 3.10
run and when the interpreter selected in the IDE uses Python 3.10.This should hopefully also simplify the handling of
VIRTUAL_ENV
andCONDA_ENV
as fallback if no python version is provided.Test Plan
Existing tests. I did move some tests from
ProjectMetadata
to CLI tests because keeping them in the metadata tests would have required increasing the visibility of many fields.