Skip to content

Commit 9cced9a

Browse files
[pyupgrade] Remove mentions of variance related to fix safety (UP040, UP047) (astral-sh#29592)
Mentioned in astral-sh#29486 Removes the incorrect descriptions from UP040 and UP047 that mention variance. This was purely decorative and never had any function, so removing it is perfectly safe. No further clarification added - variance is quite complicated and the user doesn't need to know about (decided in the issue). This is my first PR here, so I probably did something wrong while making it and I am open to all feedback. --------- Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com>
1 parent 008d452 commit 9cced9a

2 files changed

Lines changed: 7 additions & 14 deletions

File tree

‎crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_generic_function.rs‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,11 @@ use super::{DisplayTypeVars, TypeVarReferenceVisitor, check_type_vars, in_nested
3232
///
3333
/// ## Fix safety
3434
///
35-
/// This fix is marked unsafe, as [PEP 695] uses inferred variance for type parameters, instead of
36-
/// the `covariant` and `contravariant` keywords used by `TypeVar` variables. As such, replacing a
37-
/// `TypeVar` variable with an inline type parameter may change its variance.
38-
///
39-
/// Additionally, if the rule cannot determine whether a parameter annotation corresponds to a type
40-
/// variable (e.g. for a type imported from another module), it will not add the type to the generic
41-
/// type parameter list. This causes the function to have a mix of old-style type variables and
42-
/// new-style generic type parameters, which will be rejected by type checkers.
35+
/// This fix is marked unsafe because the rule may be unable to determine whether a parameter
36+
/// annotation corresponds to a type variable (e.g. for a type imported from another module). In
37+
/// that case, the fix does not add the type to the generic type parameter list. This causes the
38+
/// function to have a mix of old-style type variables and new-style generic type parameters, which
39+
/// will be rejected by type checkers.
4340
///
4441
/// ## Example
4542
///

‎crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_type_alias.rs‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ use super::{
2929
/// support for generics.
3030
///
3131
/// ## Known problems
32-
/// [PEP 695] uses inferred variance for type parameters, instead of the
33-
/// `covariant` and `contravariant` keywords used by `TypeVar` variables. As
34-
/// such, rewriting a type alias using a PEP-695 `type` statement may change
35-
/// the variance of the alias's type parameters.
3632
///
3733
/// Unlike type aliases that use simple assignments, definitions created using
3834
/// [PEP 695] `type` statements cannot be used as drop-in replacements at
@@ -62,8 +58,8 @@ use super::{
6258
///
6359
/// ## Fix safety
6460
///
65-
/// This fix is always marked unsafe because it can change runtime behavior and type-checking
66-
/// semantics, as described above. It may also remove comments.
61+
/// This fix is always marked unsafe because it can change runtime behavior, as described above.
62+
/// It may also remove comments.
6763
///
6864
/// The rule also cannot inspect type variables defined in another module. For `TypeAlias`
6965
/// annotations, this means the fix may fail to convert legacy type variables to type parameters,

0 commit comments

Comments
 (0)