-
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
[minor] Simplify some ExprStringLiteral
creation logic
#15775
Merged
Merged
+12
−18
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
SIM108 | 22 | 11 | 11 | 0 | 0 |
FLY002 | 2 | 1 | 1 | 0 | 0 |
SIM401 | 2 | 1 | 1 | 0 | 0 |
SIM103 | 2 | 1 | 1 | 0 | 0 |
RUF005 | 2 | 1 | 1 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+71 -71 violations, +0 -0 fixes in 4 projects; 51 projects unchanged)
apache/airflow (+2 -2 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL
+ dev/breeze/src/airflow_breeze/global_constants.py:591:25: FLY002 Consider `"common.compat cncf.kubernetes"` instead of string join - dev/breeze/src/airflow_breeze/global_constants.py:591:25: FLY002 Consider `'common.compat cncf.kubernetes'` instead of string join - providers/src/airflow/providers/google/suite/hooks/drive.py:194:13: SIM108 Use ternary operator `path = f"{file_info['name']}" if current_file_id == file_id else f"{file_info['name']}/{path}"` instead of `if`-`else`-block + providers/src/airflow/providers/google/suite/hooks/drive.py:194:13: SIM108 Use ternary operator `path = f'{file_info["name"]}' if current_file_id == file_id else f'{file_info["name"]}/{path}'` instead of `if`-`else`-block
binary-husky/gpt_academic (+3 -3 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview
- crazy_functions/diagram_fns/file_tree.py:22:9: SIM108 Use ternary operator `suf = "..." if len(comment) > self.comment_maxlen_show else ""` instead of `if`-`else`-block + crazy_functions/diagram_fns/file_tree.py:22:9: SIM108 Use ternary operator `suf = '...' if len(comment) > self.comment_maxlen_show else ''` instead of `if`-`else`-block + main.py:139:39: SIM401 Use `functional[k].get("Color", "secondary")` instead of an `if` block - main.py:139:39: SIM401 Use `functional[k].get('Color', 'secondary')` instead of an `if` block - request_llms/bridge_taichu.py:12:5: SIM103 Return the condition `TAICHU_API_KEY != ""` directly + request_llms/bridge_taichu.py:12:5: SIM103 Return the condition `TAICHU_API_KEY != ''` directly
bokeh/bokeh (+65 -65 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL
+ examples/output/apis/components_themed.py:89:6: FURB103 `open` and `write` should be replaced by `Path(filename).write_text(html, encoding="utf-8")` - examples/output/apis/components_themed.py:89:6: FURB103 `open` and `write` should be replaced by `Path(filename).write_text(html, encoding='utf-8')` + examples/output/jupyter/push_notebook/Numba Image Example.ipynb:cell 20:1:10: RUF005 Consider `["none", *sorted(kernels.keys())]` instead of concatenation - examples/output/jupyter/push_notebook/Numba Image Example.ipynb:cell 20:1:10: RUF005 Consider `['none', *sorted(kernels.keys())]` instead of concatenation + examples/server/app/movies/main.py:28:6: FURB101 `open` and `read` should be replaced by `Path(join(dirname(__file__), "razzies-clean.csv")).read_text()` - examples/server/app/movies/main.py:28:6: FURB101 `open` and `read` should be replaced by `Path(join(dirname(__file__), 'razzies-clean.csv')).read_text()` + examples/server/app/movies/main.py:83:25: PLC1901 `director_val != ""` can be simplified to `director_val` as an empty string is falsey - examples/server/app/movies/main.py:83:25: PLC1901 `director_val != ''` can be simplified to `director_val` as an empty string is falsey + examples/server/app/movies/main.py:85:21: PLC1901 `cast_val != ""` can be simplified to `cast_val` as an empty string is falsey - examples/server/app/movies/main.py:85:21: PLC1901 `cast_val != ''` can be simplified to `cast_val` as an empty string is falsey + src/bokeh/application/handlers/directory.py:123:18: FURB101 `open` and `read` should be replaced by `Path(init_py).read_text(encoding="utf8")` - src/bokeh/application/handlers/directory.py:123:18: FURB101 `open` and `read` should be replaced by `Path(init_py).read_text(encoding='utf8')` + src/bokeh/command/subcommands/file_output.py:134:9: SIM108 Use ternary operator `base = "index" if route == "/" else route[1:]` instead of `if`-`else`-block - src/bokeh/command/subcommands/file_output.py:134:9: SIM108 Use ternary operator `base = 'index' if route == '/' else route[1:]` instead of `if`-`else`-block + src/bokeh/command/subcommands/file_output.py:175:22: FURB103 `open` and `write` should be replaced by `Path(filename).write_text(content, encoding="utf-8")` - src/bokeh/command/subcommands/file_output.py:175:22: FURB103 `open` and `write` should be replaced by `Path(filename).write_text(content, encoding='utf-8')` + src/bokeh/core/json_encoder.py:153:5: SIM108 Use ternary operator `separators = (",", ": ") if pretty else (",", ":")` instead of `if`-`else`-block - src/bokeh/core/json_encoder.py:153:5: SIM108 Use ternary operator `separators = (',', ': ') if pretty else (',', ':')` instead of `if`-`else`-block + src/bokeh/io/export.py:264:14: FURB103 `open` and `write` should be replaced by `Path(tmp.path).write_text(html, encoding="utf-8")` - src/bokeh/io/export.py:264:14: FURB103 `open` and `write` should be replaced by `Path(tmp.path).write_text(html, encoding='utf-8')` + src/bokeh/io/export.py:294:14: FURB103 `open` and `write` should be replaced by `Path(tmp.path).write_text(html, encoding="utf-8")` - src/bokeh/io/export.py:294:14: FURB103 `open` and `write` should be replaced by `Path(tmp.path).write_text(html, encoding='utf-8')` + src/bokeh/io/export.py:311:14: FURB103 `open` and `write` should be replaced by `Path(tmp.path).write_text(html, encoding="utf-8")` - src/bokeh/io/export.py:311:14: FURB103 `open` and `write` should be replaced by `Path(tmp.path).write_text(html, encoding='utf-8')` ... 7 additional changes omitted for rule FURB103 + src/bokeh/models/callbacks.py:200:14: FURB101 `open` and `read` should be replaced by `Path(path).read_text(encoding="utf-8")` - src/bokeh/models/callbacks.py:200:14: FURB101 `open` and `read` should be replaced by `Path(path).read_text(encoding='utf-8')` + src/bokeh/plotting/_graph.py:105:5: SIM108 Use ternary operator `sedge_visuals = pop_visuals(MultiLine, kwargs, prefix="edge_selection_", defaults=edge_visuals) if any(x.startswith('edge_selection_') for x in kwargs) else None` instead of `if`-`else`-block - src/bokeh/plotting/_graph.py:105:5: SIM108 Use ternary operator `sedge_visuals = pop_visuals(MultiLine, kwargs, prefix='edge_selection_', defaults=edge_visuals) if any(x.startswith('edge_selection_') for x in kwargs) else None` instead of `if`-`else`-block + src/bokeh/plotting/_graph.py:110:5: SIM108 Use ternary operator `hedge_visuals = pop_visuals(MultiLine, kwargs, prefix="edge_hover_", defaults=edge_visuals) if any(x.startswith('edge_hover_') for x in kwargs) else None` instead of `if`-`else`-block - src/bokeh/plotting/_graph.py:110:5: SIM108 Use ternary operator `hedge_visuals = pop_visuals(MultiLine, kwargs, prefix='edge_hover_', defaults=edge_visuals) if any(x.startswith('edge_hover_') for x in kwargs) else None` instead of `if`-`else`-block + src/bokeh/plotting/_graph.py:93:5: SIM108 Use ternary operator `hnode_visuals = pop_visuals(marker_type, kwargs, prefix="node_hover_", defaults=node_visuals) if any(x.startswith('node_hover_') for x in kwargs) else None` instead of `if`-`else`-block - src/bokeh/plotting/_graph.py:93:5: SIM108 Use ternary operator `hnode_visuals = pop_visuals(marker_type, kwargs, prefix='node_hover_', defaults=node_visuals) if any(x.startswith('node_hover_') for x in kwargs) else None` instead of `if`-`else`-block ... 7 additional changes omitted for rule SIM108 + src/bokeh/plotting/_tools.py:188:20: PLC1901 `tool == ""` can be simplified to `not tool` as an empty string is falsey - src/bokeh/plotting/_tools.py:188:20: PLC1901 `tool == ''` can be simplified to `not tool` as an empty string is falsey + src/bokeh/sampledata/us_holidays.py:79:10: FURB101 `open` and `read` should be replaced by `Path(package_path("USHolidays.ics")).read_text()` - src/bokeh/sampledata/us_holidays.py:79:10: FURB101 `open` and `read` should be replaced by `Path(package_path('USHolidays.ics')).read_text()` + src/bokeh/server/util.py:151:28: PLC1901 `parts[0] == ""` can be simplified to `not parts[0]` as an empty string is falsey - src/bokeh/server/util.py:151:28: PLC1901 `parts[0] == ''` can be simplified to `not parts[0]` as an empty string is falsey + src/bokeh/server/util.py:159:28: PLC1901 `parts[0] == ""` can be simplified to `not parts[0]` as an empty string is falsey - src/bokeh/server/util.py:159:28: PLC1901 `parts[0] == ''` can be simplified to `not parts[0]` as an empty string is falsey ... 77 additional changes omitted for rule PLC1901 + src/bokeh/util/compiler.py:194:14: FURB101 `open` and `read` should be replaced by `Path(path).read_text(encoding="utf-8")` - src/bokeh/util/compiler.py:194:14: FURB101 `open` and `read` should be replaced by `Path(path).read_text(encoding='utf-8')` ... 1 additional changes omitted for rule FURB101 ... 88 additional changes omitted for project
zulip/zulip (+1 -1 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL
+ scripts/lib/sharding.py:65:21: SIM108 Use ternary operator `host = shard if "." in shard else f'{shard}.{external_host}'` instead of `if`-`else`-block - scripts/lib/sharding.py:65:21: SIM108 Use ternary operator `host = shard if '.' in shard else f'{shard}.{external_host}'` instead of `if`-`else`-block
Changes by rule (8 rules affected)
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PLC1901 | 86 | 43 | 43 | 0 | 0 |
SIM108 | 22 | 11 | 11 | 0 | 0 |
FURB103 | 16 | 8 | 8 | 0 | 0 |
FURB101 | 10 | 5 | 5 | 0 | 0 |
FLY002 | 2 | 1 | 1 | 0 | 0 |
SIM401 | 2 | 1 | 1 | 0 | 0 |
SIM103 | 2 | 1 | 1 | 0 | 0 |
RUF005 | 2 | 1 | 1 | 0 | 0 |
Formatter (stable)
✅ ecosystem check detected no format changes.
Formatter (preview)
✅ ecosystem check detected no format changes.
dcreager
added a commit
that referenced
this pull request
Jan 29, 2025
* main: [red-knot] Extend instance-attribute tests (#15808) Fix formatter warning message for `flake8-quotes` option (#15788) [`flake8-bugbear`] Exempt `NewType` calls where the original type is immutable (`B008`) (#15765) Add missing config docstrings (#15803) [`refurb`] Do not emit diagnostic when loop variables are used outside loop body (`FURB122`) (#15757) [`ruff`] Check for shadowed `map` before suggesting fix (`RUF058`) (#15790) [red-knot] Do not use explicit `knot_extensions.Unknown` declaration (#15787) Preserve quotes in generated byte strings (#15778) [minor] Simplify some `ExprStringLiteral` creation logic (#15775) Preserve quote style in generated code (#15726) Rename internal helper functions (#15771) [`airflow`] Extend airflow context parameter check for `BaseOperator.execute` (`AIR302`) (#15713) Implement tab autocomplete for `ruff config` (#15603)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
A couple of minor opportunities for simplification that I spotted as a result of reviewing #15726
Test Plan
cargo test