Skip to content
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

Gate PEP604 isinstance rewrites behind Python 3.10+ #3327

Merged
merged 1 commit into from
Mar 3, 2023

Conversation

charliermarsh
Copy link
Member

Closes #3326.

@@ -2631,7 +2631,10 @@ where
if self.settings.rules.enabled(&Rule::OSErrorAlias) {
pyupgrade::rules::os_error_alias(self, &expr);
}
if self.settings.rules.enabled(&Rule::IsinstanceWithTuple) {
if self.settings.rules.enabled(&Rule::IsinstanceWithTuple)
&& !self.settings.pyupgrade.keep_runtime_typing
Copy link
Member Author

Choose a reason for hiding this comment

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

This flag is redundant, but it's already redundant for the other PEP 604 rule (since it's equivalent to turning off the rule), so I think it makes sense to be consistent.

@charliermarsh charliermarsh enabled auto-merge (squash) March 3, 2023 22:15
Comment on lines 26 to 31
/// `from __future__ import annotations`. Note that this setting is only
/// applicable when the target Python version is below 3.9 and 3.10
/// respectively, and enabling it is equivalent to disabling
/// `use-pep585-annotation` (`UP006`) and `use-pep604-annotation`
/// (`UP007`) entirely.
/// `use-pep585-annotation` (`UP006`), `use-pep604-annotation`
/// (`UP007`), and `use-pep604-isinstance` (`UP038`) entirely.
pub keep_runtime_typing: Option<bool>,
Copy link
Contributor

Choose a reason for hiding this comment

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

An isinstance call is not an annotation, isn’t affected by from __future__ import annotations, and isn’t visible to typing.get_type_hints (the upstream motivation for this flag: asottile/pyupgrade#387), so I’m not sure the same logic applies.

Copy link
Member Author

Choose a reason for hiding this comment

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

Don't feel strongly! I thought it could feel inconsistent or surprising to users but your argument makes sense.

#3328

@charliermarsh charliermarsh merged commit b5b26d5 into main Mar 3, 2023
@charliermarsh charliermarsh deleted the charlie/gate branch March 3, 2023 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gate PEP 646 isinstance checks on Python version
2 participants