-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
@@ -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 |
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 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.
e05c08d
to
9f49431
Compare
/// `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>, |
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.
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.
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.
Don't feel strongly! I thought it could feel inconsistent or surprising to users but your argument makes sense.
Closes #3326.