Skip to content

Add CLI flag to override typeshed #488

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

krikera
Copy link

@krikera krikera commented Jun 14, 2025

Add --typeshed-path flag to pyrefly check command for testing typeshed upgrades and custom typeshed modifications.

  • Add typeshed_path CLI argument to ConfigOverrideArgs
  • Add typeshed_path field to ConfigFile struct
  • Wire custom typeshed lookup into find_import() logic
  • Custom typeshed takes precedence over bundled typeshed

Fixes #483

Add --typeshed-path flag to pyrefly check command for testing typeshed
upgrades and custom typeshed modifications.

- Add typeshed_path CLI argument to ConfigOverrideArgs
- Add typeshed_path field to ConfigFile struct
- Wire custom typeshed lookup into find_import() logic
- Custom typeshed takes precedence over bundled typeshed
- Falls back gracefully to bundled typeshed if module not found

Fixes facebook#483
Copy link
Contributor

@connernilsen connernilsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @krikera, thanks for doing this! Just a few things that need to be changed before we can get this in.

Once you're able to fix them, please re-request my review and I'll come check it out!

Comment on lines +367 to +387
} else if let Some(path) = typeshed()
.map_err(|err| FindError::not_found(err, module))?
.find(module)
{
Ok(path)
} else if let Some(path) = find_module_in_search_path(module, self.fallback_search_path.iter()) {
Ok(path)
} else if let Some(path) = find_module_in_site_package_path(
module,
self.site_package_path(),
self.use_untyped_imports,
self.ignore_missing_source,
)? {
Ok(path)
} else {
Err(FindError::import_lookup_path(
self.structured_import_lookup_path(),
module,
&self.source,
))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, it looks like this part might have been duplicated from below. Can you remove this?

module,
&self.source,
))
}
} else if let Some(path) = typeshed()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only use the builtin typeshed if one isn't provided. Can we add an extra condition for that here?

} else if self.typeshed_path.is_none() && let Some(path) = ...

@@ -174,6 +174,9 @@ struct ConfigOverrideArgs {
/// after first checking `search_path` and `typeshed`.
#[arg(long, env = clap_env("SITE_PACKAGE_PATH"))]
site_package_path: Option<Vec<PathBuf>>,
/// Override the bundled typeshed with a custom path.
#[arg(long = "typeshed-path", env = clap_env("TYPESHED_PATH"))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: arg(long, ...) does the same thing as arg(long = "typeshed-path", ...), but specifying "typeshed-path" is more prone to typos/less resilient to refactors. Can we just leave this as arg(long, ...)?

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

Successfully merging this pull request may close these issues.

Add CLI flag to override typeshed
3 participants