-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[flake8-pyi
] Apply redundant-numeric-union
to more type expressions (PYI041
)
#14332
[flake8-pyi
] Apply redundant-numeric-union
to more type expressions (PYI041
)
#14332
Conversation
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PYI041 | 102 | 102 | 0 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+66 -0 violations, +0 -0 fixes in 10 projects; 45 projects unchanged)
PlasmaPy/PlasmaPy (+4 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview
+ src/plasmapy/analysis/swept_langmuir/floating_potential.py:221:37: PYI041 [*] Use `float` instead of `int | float` + src/plasmapy/formulary/densities.py:159:32: PYI041 [*] Use `float` instead of `int | float` + tests/plasma/test_grids.py:261:32: PYI041 [*] Use `float` instead of `int | float` + tests/plasma/test_grids.py:302:32: PYI041 [*] Use `float` instead of `int | float`
apache/airflow (+30 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL
+ airflow/configuration.py:1168:10: PYI041 [*] Use `float` instead of `int | float` + airflow/configuration.py:69:14: PYI041 [*] Use `float` instead of `int | float` + airflow/jobs/job.py:63:62: PYI041 [*] Use `float` instead of `int | float` + airflow/jobs/job.py:65:35: PYI041 [*] Use `float` instead of `int | float` + airflow/metrics/otel_logger.py:53:15: PYI041 [*] Use `float` instead of `int | float` + airflow/metrics/protocols.py:26:13: PYI041 [*] Use `float` instead of `int | float` + airflow/policies.py:109:54: PYI041 [*] Use `float` instead of `int | float` + airflow/serialization/helpers.py:28:65: PYI041 [*] Use `float` instead of `int | float` + airflow/serialization/serde.py:59:5: PYI041 [*] Use `float` instead of `int | float` + airflow/utils/log/colored_log.py:60:33: PYI041 [*] Use `float` instead of `int | float` + providers/src/airflow/providers/alibaba/cloud/hooks/analyticdb_spark.py:201:24: PYI041 [*] Use `float` instead of `int | float` + providers/src/airflow/providers/alibaba/cloud/hooks/analyticdb_spark.py:301:54: PYI041 [*] Use `float` instead of `int | float` + providers/src/airflow/providers/alibaba/cloud/operators/analyticdb_spark.py:183:24: PYI041 [*] Use `float` instead of `int | float` + providers/src/airflow/providers/amazon/aws/hooks/glue.py:111:31: PYI041 [*] Use `float` instead of `int | float` + providers/src/airflow/providers/apache/livy/hooks/livy.py:340:24: PYI041 [*] Use `float` instead of `int | float` + providers/src/airflow/providers/apache/livy/hooks/livy.py:429:54: PYI041 [*] Use `float` instead of `int | float` + providers/src/airflow/providers/apache/livy/hooks/livy.py:725:24: PYI041 [*] Use `float` instead of `int | float` + providers/src/airflow/providers/apache/livy/hooks/livy.py:810:54: PYI041 [*] Use `float` instead of `int | float` + providers/src/airflow/providers/apache/livy/operators/livy.py:77:24: PYI041 [*] Use `float` instead of `int | float` + providers/src/airflow/providers/google/cloud/hooks/vertex_ai/custom_job.py:1043:20: PYI041 [*] Use `float` instead of `int | float` + providers/src/airflow/providers/google/cloud/hooks/vertex_ai/custom_job.py:1431:20: PYI041 [*] Use `float` instead of `int | float` + providers/src/airflow/providers/google/cloud/hooks/vertex_ai/custom_job.py:1815:20: PYI041 [*] Use `float` instead of `int | float` ... 8 additional changes omitted for project
apache/superset (+11 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL
+ superset/connectors/sqla/models.py:1673:10: PYI041 [*] Use `float` instead of `int | float` + superset/db_engine_specs/base.py:875:10: PYI041 [*] Use `float` instead of `int | float` + superset/distributed_lock/utils.py:31:15: PYI041 [*] Use `float` instead of `int | float` + superset/models/helpers.py:900:10: PYI041 [*] Use `float` instead of `int | float` + superset/superset_typing.py:105:15: PYI041 [*] Use `float` instead of `int | float` + superset/utils/core.py:349:53: PYI041 [*] Use `float` instead of `int | float` + superset/utils/pandas_postprocessing/boxplot.py:34:20: PYI041 [*] Use `float` instead of `int | float` + superset/utils/pandas_postprocessing/boxplot.py:34:46: PYI041 [*] Use `float` instead of `int | float` + superset/utils/pandas_postprocessing/boxplot.py:34:65: PYI041 [*] Use `float` instead of `int | float` + superset/utils/pandas_postprocessing/resample.py:30:26: PYI041 [*] Use `float` instead of `int | float` ... 1 additional changes omitted for project
bokeh/bokeh (+2 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL
+ src/bokeh/core/property/numeric.py:53:24: PYI041 [*] Use `float` instead of `int | float` + tests/support/util/compare.py:50:18: PYI041 [*] Use `float` instead of `int | float`
latchbio/latch (+7 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview
+ src/latch/registry/types.py:37:43: PYI041 [*] Use `float` instead of `int | float` + src/latch/types/json.py:11:24: PYI041 [*] Use `float` instead of `int | float` + src/latch/types/metadata.py:418:28: PYI041 [*] Use `float` instead of `int | float` + src/latch_cli/snakemake/config/utils.py:12:24: PYI041 [*] Use `float` instead of `int | float` + src/latch_cli/snakemake/config/utils.py:196:50: PYI041 [*] Use `float` instead of `int | float` + src/latch_sdk_gql/__init__.py:14:24: PYI041 [*] Use `float` instead of `int | float` + src/latch_sdk_gql/utils.py:37:28: PYI041 [*] Use `float` instead of `int | float`
python/typeshed (+3 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select E,F,FA,I,PYI,RUF,UP,W
+ stdlib/marshal.pyi:12:5: PYI041 Use `complex` instead of `int | float | complex` + stdlib/xmlrpc/client.pyi:17:5: PYI041 Use `float` instead of `int | float` + stubs/seaborn/seaborn/utils.pyi:43:5: PYI041 Use `complex` instead of `float | complex`
rotki/rotki (+1 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview
+ rotkehlchen/fval.py:8:27: PYI041 [*] Use `float` instead of `int | float`
zulip/zulip (+4 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL
+ zerver/lib/data_types.py:116:28: PYI041 [*] Use `float` instead of `int | float` + zerver/lib/drafts.py:33:16: PYI041 [*] Use `float` instead of `int | float` + zerver/openapi/markdown_extension.py:257:64: PYI041 [*] Use `float` instead of `int | float` + zilencer/views.py:588:16: PYI041 [*] Use `float` instead of `int | float`
pytest-dev/pytest (+1 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview
+ src/_pytest/mark/structures.py:472:27: PYI041 [*] Use `float` instead of `int | float`
astropy/astropy (+3 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview
+ astropy/units/typing.py:75:19: PYI041 [*] Use `float` instead of `int | float` + astropy/units/typing.py:78:24: PYI041 [*] Use `float` instead of `int | float` + astropy/units/typing.py:79:24: PYI041 [*] Use `complex` instead of `int | float | complex`
Changes by rule (1 rules affected)
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PYI041 | 66 | 66 | 0 | 0 | 0 |
Note for myself, merge #14273 after this PR lands |
16daf9d
to
c7c1125
Compare
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.
Thanks for the PR. Unfortunately, I think the premise of this PR is incorrect. As the docs for this rule state:
/// ## Why is this bad?
/// The [typing specification] states:
///
/// > Python’s numeric types `complex`, `float` and `int` are not subtypes of
/// > each other, but to support common use cases, the type system contains a
/// > straightforward shortcut: when an argument is annotated as having type
/// > `float`, an argument of type `int` is acceptable; similar, for an
/// > argument annotated as having type `complex`, arguments of type `float` or
/// > `int` are acceptable.
///
/// As such, a union that includes both `int` and `float` is redundant in the
/// specific context of a parameter annotation, as it is equivalent to a union
/// that only includes `float`. For readability and clarity, unions should omit
/// redundant elements.
Note the specific language of the typing spec there: float
is not a subtype of complex
, and int
is not a subtype of float
. You cannot always simplify the union int | float
to float
, you can only do this "in the specific context of a parameter annotation", because of a very special case that the typing system carves out for this situation
Ah, thanks for pointing that out! I wrongly assumed the scope to parameters was unintentional and that this rule applied in all type annotation contexts. |
Summary
Fixes false negatives for redundant numeric unions in other places than function arguments, eg. return types, type aliases
Splitting this change of from #14273 (will rebase once that is merged)
Test Plan
cargo test
and reviewed ecosystem results