Skip to content

Avoid inserting redundant None elements in UP045#23459

Merged
charliermarsh merged 1 commit intomainfrom
charlie/none
Mar 1, 2026
Merged

Avoid inserting redundant None elements in UP045#23459
charliermarsh merged 1 commit intomainfrom
charlie/none

Conversation

@charliermarsh
Copy link
Member

Summary

Closes #23429.

@charliermarsh charliermarsh added bug Something isn't working fixes Related to suggested fixes for violations labels Feb 21, 2026
@charliermarsh charliermarsh marked this pull request as ready for review February 21, 2026 02:01
@charliermarsh charliermarsh requested a review from ntBre February 21, 2026 02:06
@astral-sh-bot
Copy link

astral-sh-bot bot commented Feb 21, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Comment on lines +333 to +334
- bar: None | Optional[None | int] = None
89 + bar: None | int | None = None
Copy link
Member

Choose a reason for hiding this comment

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

Is this supposed to de-dupe the None here?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good call... I'll do it in a separate PR...

/// Collect all leaf elements of a chain of `BitOr` binary operations.
///
/// For example, `a | b | c` is collected as `[a, b, c]`.
fn collect_bitor_elements(expr: &Expr) -> Vec<&Expr> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use traverse_union here? It looks kind of similar.

pub fn traverse_union<'a, F>(func: &mut F, semantic: &SemanticModel, expr: &'a Expr)

Copy link
Member Author

Choose a reason for hiding this comment

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

(I don't think so, since traverse_union also traverses Union[...], and we don't want to touch those here IIUC...)

@charliermarsh charliermarsh enabled auto-merge (squash) March 1, 2026 14:59
@charliermarsh charliermarsh merged commit 808b521 into main Mar 1, 2026
41 checks passed
@charliermarsh charliermarsh deleted the charlie/none branch March 1, 2026 15:01
carljm added a commit that referenced this pull request Mar 2, 2026
* main:
  [ty] Move binary expression logic out of `builder.rs` (#23649)
  [ty] Limit recursion depth when displaying self-referential function types (#23647)
  [ty] Move comparison logic out of `builder.rs` (#23646)
  Avoid inserting redundant `None` elements in UP045 (#23459)
  [ty] Add more ParamSpec validation for `P.args` and `P.kwargs` (#23640)
  [ty] Sync vendored typeshed stubs (#23642)
  [ty] Fix inference of `t.__mro__` if `t` is an instance of `type[Any]` (#23632)
  [ty] Detect inconsistent generic base class specializations (#23615)
  [ty] Validate type variable defaults don't reference later type parameters or type parameters out of scope (#23623)
  [ty] Ban nested `Required`/`NotRequired`, and ban them both outside of `TypedDict` fields (#23627)
  [ty] Reject generic metaclasses parameterized by type variables (#23628)
  Update default Python version examples (#23605)
  fix binops with NewType of float and Unknown (#23620)
  [ty] Reject functions with PEP-695 type parameters that shadow type parameters from enclosing scopes (#23619)
  [ty] Reject ellipsis literals in odd places in type/annotation expressions (#23611)
  [ty] hash-cons `UseDefMap` fields (#23283)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fixes Related to suggested fixes for violations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UP045 fixes None | Optional[None | int] to None | None | int | None

3 participants