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

[pyupgrade] Split UP007 to two individual rules for Union and Optional (UP007, UP045) #15313

Merged
merged 7 commits into from
Jan 7, 2025

Conversation

InSyncWithFoo
Copy link
Contributor

Summary

Resolves #4858. Part of this PR was taken from #11379.

Test Plan

cargo nextest run and cargo insta test.

Copy link
Contributor

github-actions bot commented Jan 7, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+1556 -94 violations, +0 -0 fixes in 6 projects; 49 projects unchanged)

apache/airflow (+6 -2 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL

- airflow/utils/log/logging_mixin.py:175:9: PLR6301 Method `writable` could be a function, class method, or static method
+ airflow/utils/log/logging_mixin.py:175:9: PLR6301 Method `writable` could be a function, class method, or static method
+ airflow/utils/log/logging_mixin.py:1:1: D100 Missing docstring in public module
- airflow/utils/log/logging_mixin.py:1:1: D100 Missing docstring in public module
+ airflow/utils/log/logging_mixin.py:76:30: UP045 Use `X | None` for type annotations
+ airflow/utils/log/logging_mixin.py:76:52: RUF100 [*] Unused `noqa` directive (unused: `UP007`)
+ airflow/utils/log/logging_mixin.py:78:19: UP045 Use `X | None` for type annotations
+ airflow/utils/log/logging_mixin.py:78:41: RUF100 [*] Unused `noqa` directive (unused: `UP007`)

apache/superset (+79 -79 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL

- superset/async_events/async_query_manager.py:106:22: UP007 Use `X | Y` for type annotations
+ superset/async_events/async_query_manager.py:106:22: UP045 Use `X | None` for type annotations
- superset/async_events/async_query_manager.py:108:29: UP007 Use `X | Y` for type annotations
+ superset/async_events/async_query_manager.py:108:29: UP045 Use `X | None` for type annotations
- superset/async_events/async_query_manager.py:109:38: UP007 Use `X | Y` for type annotations
+ superset/async_events/async_query_manager.py:109:38: UP045 Use `X | None` for type annotations
- superset/async_events/async_query_manager.py:112:34: UP007 Use `X | Y` for type annotations
+ superset/async_events/async_query_manager.py:112:34: UP045 Use `X | None` for type annotations
- superset/async_events/async_query_manager.py:113:36: UP007 Use `X | Y` for type annotations
+ superset/async_events/async_query_manager.py:113:36: UP045 Use `X | None` for type annotations
... 148 additional changes omitted for project

ibis-project/ibis (+102 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

+ ibis/backends/bigquery/__init__.py:847:48: UP045 [*] Use `X | None` for type annotations
+ ibis/common/graph.py:171:46: UP045 [*] Use `X | None` for type annotations
+ ibis/common/graph.py:203:50: UP045 [*] Use `X | None` for type annotations
+ ibis/common/graph.py:275:41: UP045 [*] Use `X | None` for type annotations
+ ibis/common/graph.py:310:47: UP045 [*] Use `X | None` for type annotations
+ ibis/common/graph.py:359:47: UP045 [*] Use `X | None` for type annotations
+ ibis/common/graph.py:379:17: UP045 [*] Use `X | None` for type annotations
+ ibis/common/graph.py:380:18: UP045 [*] Use `X | None` for type annotations
+ ibis/common/graph.py:418:17: UP045 [*] Use `X | None` for type annotations
+ ibis/common/graph.py:419:18: UP045 [*] Use `X | None` for type annotations
... 92 additional changes omitted for project

langchain-ai/langchain (+1148 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

+ libs/core/langchain_core/caches.py:149:36: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/caches.py:167:55: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/caches.py:200:62: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/caches.py:52:55: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/caches.py:97:62: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:104:24: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:125:24: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:141:24: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:157:24: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:173:24: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:193:24: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:209:24: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:230:24: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:231:15: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:232:19: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:257:24: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:258:15: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:259:19: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:287:24: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:288:15: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:289:19: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:29:24: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:310:24: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:311:15: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:312:19: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:333:24: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:334:15: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:335:19: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:336:17: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:361:24: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:378:24: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:396:15: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:397:19: UP045 Use `X | None` for type annotations
+ libs/core/langchain_core/callbacks/base.py:46:24: UP045 Use `X | None` for type annotations
... 1114 additional changes omitted for project

latchbio/latch (+13 -13 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

- src/latch/registry/record.py:188:57: UP007 Use `X | Y` for type annotations
+ src/latch/registry/record.py:188:57: UP045 Use `X | None` for type annotations
- src/latch/registry/record.py:190:64: UP007 Use `X | Y` for type annotations
+ src/latch/registry/record.py:190:64: UP045 Use `X | None` for type annotations
- src/latch/registry/record.py:215:53: UP007 Use `X | Y` for type annotations
+ src/latch/registry/record.py:215:53: UP045 Use `X | None` for type annotations
- src/latch/registry/record.py:217:60: UP007 Use `X | Y` for type annotations
+ src/latch/registry/record.py:217:60: UP045 Use `X | None` for type annotations
- src/latch/registry/record.py:250:10: UP007 Use `X | Y` for type annotations
+ src/latch/registry/record.py:250:10: UP045 Use `X | None` for type annotations
... 16 additional changes omitted for project

lnbits/lnbits (+208 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

+ lnbits/core/models.py:102:15: UP045 Use `X | None` for type annotations
+ lnbits/core/models.py:107:20: UP045 Use `X | None` for type annotations
+ lnbits/core/models.py:108:15: UP045 Use `X | None` for type annotations
+ lnbits/core/models.py:109:15: UP045 Use `X | None` for type annotations
+ lnbits/core/models.py:110:12: UP045 Use `X | None` for type annotations
+ lnbits/core/models.py:111:19: UP045 Use `X | None` for type annotations
+ lnbits/core/models.py:112:24: UP045 Use `X | None` for type annotations
+ lnbits/core/models.py:113:19: UP045 Use `X | None` for type annotations
+ lnbits/core/models.py:114:19: UP045 Use `X | None` for type annotations
+ lnbits/core/models.py:129:19: UP045 Use `X | None` for type annotations
... 198 additional changes omitted for project

Changes by rule (5 rules affected)

code total + violation - violation + fix - fix
UP045 1552 1552 0 0 0
UP007 92 0 92 0 0
PLR6301 2 1 1 0 0
D100 2 1 1 0 0
RUF100 2 2 0 0 0

@MichaReiser MichaReiser added the breaking Breaking API change label Jan 7, 2025
@MichaReiser MichaReiser added rule Implementing or modifying a lint rule preview Related to preview mode features and removed breaking Breaking API change labels Jan 7, 2025
@MichaReiser
Copy link
Member

MichaReiser commented Jan 7, 2025

It's unclear to me why the ecosystem changes show more new UP045 violations than removed UP007 violations. Do we need to rebase this on main to get the --no-fix in ecosystem checks?

@InSyncWithFoo
Copy link
Contributor Author

It's unclear to me why the ecosystem changes show more new UP045 violations than removed UP007 violations.

Some of the projects have ignore = ["UP007"] (@Inbits/Inbits, @ibis-project/ibis). This PR seems to be making a good change, given the comments nearby.

@MichaReiser
Copy link
Member

Ah, that makes sense.

@MichaReiser MichaReiser enabled auto-merge (squash) January 7, 2025 10:19
@MichaReiser MichaReiser merged commit 0dc00e6 into astral-sh:main Jan 7, 2025
20 checks passed
@InSyncWithFoo InSyncWithFoo deleted the UP007 branch January 7, 2025 14:49
@InSyncWithFoo
Copy link
Contributor Author

@MichaReiser I think #11379 can be closed now.

dcreager added a commit that referenced this pull request Jan 7, 2025
* main:
  Use uv consistently throughout the documentation (#15302)
  [red-knot] Eagerly normalize `type[]` types (#15272)
  [`pyupgrade`] Split `UP007` to two individual rules for `Union` and `Optional` (`UP007`, `UP045`) (#15313)
  [red-knot] Improve symbol-lookup tracing (#14907)
  [red-knot] improve type shrinking coverage in red-knot property tests (#15297)
  [`flake8-return`] Recognize functions returning `Never` as non-returning (`RET503`) (#15298)
  [`flake8-bugbear`] Implement `class-as-data-structure` (`B903`) (#9601)
  Avoid treating newline-separated sections as sub-sections (#15311)
  Remove call when removing final argument from `format` (#15309)
  Don't enforce `object-without-hash-method` in stubs (#15310)
  Don't special-case class instances in binary expression inference (#15161)
  Upgrade zizmor to the latest version in CI (#15300)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preview Related to preview mode features rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UP007: opt out of Optional
2 participants