Improve IPython escape command parsing logic#10873
Conversation
What does that mean. Where does it not match the old parsing logic and why is that? |
| TokenKind::Type => Stmt::TypeAlias(self.parse_type_alias_statement()), | ||
| TokenKind::EscapeCommand if self.mode == Mode::Ipython => { | ||
| TokenKind::IpyEscapeCommand => { | ||
| Stmt::IpyEscapeCommand(self.parse_ipython_escape_command_statement()) | ||
| } |
There was a problem hiding this comment.
I don't think we should let it use the fallback logic and instead handle it in parse_ipython_escape_command_statement function.
| } else if !matches!( | ||
| parsed_expr.expr, | ||
| Expr::Name(_) | Expr::Attribute(_) | Expr::Subscript(_) | ||
| ) { | ||
| self.add_error( | ||
| ParseErrorType::OtherError( | ||
| "Expected name, subscript or attribute expression in help end escape command" | ||
| .to_string(), | ||
| ), | ||
| parsed_expr, | ||
| ); | ||
| } |
There was a problem hiding this comment.
I haven't migrated the unparse_expr used in the old parser.
There was a problem hiding this comment.
Nevermind, it wasn't too much work migrating it.
9b49864 to
668b07d
Compare
62a9cfc to
04337ac
Compare
668b07d to
ea0b7eb
Compare
04337ac to
90fd01e
Compare
CodSpeed Performance ReportMerging #10873 will degrade performances by 5.25%Comparing Summary
Benchmarks breakdown
|
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| SIM103 | 14 | 7 | 7 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+97 -237 violations, +0 -0 fixes in 12 projects; 32 projects unchanged)
apache/airflow (+24 -62 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL
- airflow/cli/commands/kubernetes_command.py:70:14: FURB103 `open` and `write` should be replaced by `Path(...).write_text(yaml.dump(sanitized_pod))` - airflow/cli/commands/pool_command.py:147:10: FURB103 `open` and `write` should be replaced by `Path(filepath)....` - airflow/configuration.py:1309:13: SIM103 Return the condition `not value is None` directly + airflow/configuration.py:1309:13: SIM103 Return the condition `value is None` directly - airflow/dag_processing/manager.py:1248:9: SIM103 Return the condition `not self._num_run < self._max_runs` directly + airflow/dag_processing/manager.py:1248:9: SIM103 Return the condition `self._num_run < self._max_runs` directly - airflow/example_dags/example_kubernetes_executor.py:91:18: FURB103 `open` and `write` should be replaced by `Path("/foo/volume_mount_test.txt").write_text("Hello")` + airflow/migrations/env.py:33:5: SIM103 Return the condition directly - airflow/migrations/env.py:33:5: SIM103 Return the negated condition directly + airflow/models/taskinstance.py:385:5: SIM103 Return the condition `isinstance(value, (bytearray, bytes, str))` directly ... 42 additional changes omitted for rule SIM103 - airflow/providers/databricks/operators/databricks_sql.py:152:18: FURB103 `open` and `write` should be replaced by `Path(self._output_path)....` - airflow/providers/fab/auth_manager/security_manager/override.py:776:18: FURB103 `open` and `write` should be replaced by `Path(password_path).write_text(password)` ... 74 additional changes omitted for project
bokeh/bokeh (+1 -42 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL
- examples/models/basic_plot.py:42:10: FURB103 `open` and `write` should be replaced by `Path(filename)....` - examples/models/buttons.py:75:10: FURB103 `open` and `write` should be replaced by `Path(filename).write_text(file_html(title="Button widgets", doc))` - examples/models/calendars.py:104:10: FURB103 `open` and `write` should be replaced by `Path(filename).write_text(file_html(title="Calendar 2014", doc))` - examples/models/colors.py:69:10: FURB103 `open` and `write` should be replaced by `Path(filename)....` - examples/models/custom.py:117:10: FURB103 `open` and `write` should be replaced by `Path(filename)....` - examples/models/customjs.py:38:10: FURB103 `open` and `write` should be replaced by `Path(filename)....` ... 36 additional changes omitted for rule FURB103 - examples/server/app/server_auth/auth.py:40:9: SIM103 Return the condition `bool(username == "bokeh" and password == "bokeh")` directly + examples/server/app/server_auth/auth.py:40:9: SIM103 Return the condition `username == "bokeh" and password == "bokeh"` directly ... 35 additional changes omitted for project
demisto/content (+25 -25 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview
+ Packs/ARIAPacketIntelligence/Integrations/ARIAPacketIntelligence/ARIAPacketIntelligence.py:763:9: SIM103 Return the condition `RDL is None` directly - Packs/ARIAPacketIntelligence/Integrations/ARIAPacketIntelligence/ARIAPacketIntelligence.py:763:9: SIM103 Return the negated condition directly - Packs/ARIAPacketIntelligence/Integrations/ARIAPacketIntelligence/ARIAPacketIntelligence.py:778:9: SIM103 Return the condition `not not self._valid(self.rcs)` directly + Packs/ARIAPacketIntelligence/Integrations/ARIAPacketIntelligence/ARIAPacketIntelligence.py:778:9: SIM103 Return the condition `not self._valid(self.rcs)` directly - Packs/Active_Directory_Query/Integrations/Active_Directory_Query/Active_Directory_Query.py:347:5: SIM103 Return the condition `bool(entries.get('flat'))` directly + Packs/Active_Directory_Query/Integrations/Active_Directory_Query/Active_Directory_Query.py:347:5: SIM103 Return the condition `entries.get('flat')` directly + Packs/Base/Scripts/DBotTrainClustering/DBotTrainClustering.py:540:5: SIM103 Return the condition `not 1 < n_labels < n_samples` directly - Packs/Base/Scripts/DBotTrainClustering/DBotTrainClustering.py:540:5: SIM103 Return the condition `not not 1 < n_labels < n_samples` directly - Packs/CheckPhish/Integrations/CheckPhish/CheckPhish.py:144:5: SIM103 Return the condition `bool(res and res['status'] == DONE_STATUS)` directly + Packs/CheckPhish/Integrations/CheckPhish/CheckPhish.py:144:5: SIM103 Return the condition `res and res['status'] == DONE_STATUS` directly ... 40 additional changes omitted for project
freedomofpress/securedrop (+6 -6 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview
- journalist_gui/journalist_gui/SecureDropUpdater.py:23:5: SIM103 Return the condition `not pwd_flag == "NP"` directly + journalist_gui/journalist_gui/SecureDropUpdater.py:23:5: SIM103 Return the condition `pwd_flag == "NP"` directly - securedrop/pretty_bad_protocol/_parsers.py:1008:9: SIM103 Return the condition `bool(self.fingerprint)` directly + securedrop/pretty_bad_protocol/_parsers.py:1008:9: SIM103 Return the condition `self.fingerprint` directly + securedrop/pretty_bad_protocol/_parsers.py:1321:9: SIM103 Return the condition `len(self.fingerprints) == 0` directly - securedrop/pretty_bad_protocol/_parsers.py:1321:9: SIM103 Return the condition `not len(self.fingerprints) == 0` directly + securedrop/pretty_bad_protocol/_parsers.py:1425:9: SIM103 Return the condition `len(self.fingerprints) == 0` directly - securedrop/pretty_bad_protocol/_parsers.py:1425:9: SIM103 Return the condition `not len(self.fingerprints) == 0` directly - securedrop/pretty_bad_protocol/_parsers.py:1788:9: SIM103 Return the condition `bool(self.ok)` directly + securedrop/pretty_bad_protocol/_parsers.py:1788:9: SIM103 Return the condition `self.ok` directly ... 2 additional changes omitted for project
milvus-io/pymilvus (+5 -5 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview
+ pymilvus/client/check.py:166:5: SIM103 Return the condition `(end_date - start_date).days < 0` directly - pymilvus/client/check.py:166:5: SIM103 Return the condition `not (end_date - start_date).days < 0` directly + pymilvus/client/check.py:20:5: SIM103 Return the condition `not is_legal_host(a[0]) or not is_legal_port(a[1])` directly - pymilvus/client/check.py:20:5: SIM103 Return the negated condition directly + pymilvus/client/check.py:27:5: SIM103 Return the condition directly - pymilvus/client/check.py:27:5: SIM103 Return the negated condition directly + pymilvus/orm/collection.py:1445:9: SIM103 Return the condition directly - pymilvus/orm/collection.py:1445:9: SIM103 Return the negated condition directly + pymilvus/orm/iterator.py:458:9: SIM103 Return the condition `cached_page is None or len(cached_page) < count` directly - pymilvus/orm/iterator.py:458:9: SIM103 Return the negated condition directly
mlflow/mlflow (+9 -9 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview
+ mlflow/sklearn/utils.py:929:9: SIM103 Return the condition `not len(c.__abstractmethods__)` directly - mlflow/sklearn/utils.py:929:9: SIM103 Return the condition `not not len(c.__abstractmethods__)` directly + mlflow/tracking/_tracking_service/utils.py:25:5: SIM103 Return the condition `_tracking_uri or MLFLOW_TRACKING_URI.get()` directly - mlflow/tracking/_tracking_service/utils.py:25:5: SIM103 Return the condition `bool(_tracking_uri or MLFLOW_TRACKING_URI.get())` directly + mlflow/transformers/__init__.py:1473:5: SIM103 Return the condition directly - mlflow/transformers/__init__.py:1473:5: SIM103 Return the negated condition directly + mlflow/utils/logging_utils.py:101:9: SIM103 Return the condition directly - mlflow/utils/logging_utils.py:101:9: SIM103 Return the negated condition directly + mlflow/utils/search_utils.py:1199:9: SIM103 Return the condition directly - mlflow/utils/search_utils.py:1199:9: SIM103 Return the negated condition directly ... 8 additional changes omitted for project
pypa/cibuildwheel (+1 -1 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview
+ cibuildwheel/projectfiles.py:42:5: SIM103 Return the condition `len(consts) != 1` directly - cibuildwheel/projectfiles.py:42:5: SIM103 Return the condition `not len(consts) != 1` directly
reflex-dev/reflex (+1 -1 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview
- reflex/utils/telemetry.py:85:5: SIM103 Return the condition `not should_skip_compile()` directly + reflex/utils/telemetry.py:85:5: SIM103 Return the condition `should_skip_compile()` directly
rotki/rotki (+0 -19 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview
- package.py:734:14: FURB103 `open` and `write` should be replaced by `Path(p12).write_bytes(certificate_data)` - rotkehlchen/chain/ethereum/airdrops.py:248:18: FURB103 `open` and `write` should be replaced by `Path(filename).write_text(response.text, encoding='utf8')` - rotkehlchen/chain/ethereum/airdrops.py:284:14: FURB103 `open` and `write` should be replaced by `Path(filename)....` - rotkehlchen/chain/ethereum/utils.py:224:10: FURB103 `open` and `write` should be replaced by `Path(avatars_dir / f'{ens_name}.png').write_bytes(avatar)` - rotkehlchen/db/dbhandler.py:300:14: FURB103 `open` and `write` should be replaced by `Path(self.user_data_dir / DBINFO_FILENAME).write_text(rlk_jsondumps(dbinfo), encoding='utf8')` - rotkehlchen/db/dbhandler.py:593:18: FURB103 `open` and `write` should be replaced by `Path(tempdbpath).write_bytes(unencrypted_db_data)` - rotkehlchen/icons.py:190:14: FURB103 `open` and `write` should be replaced by `Path(self.iconfile_path(asset)).write_bytes(response.content)` - rotkehlchen/tests/api/test_caching.py:42:10: FURB103 `open` and `write` should be replaced by `Path(f'{icons_dir}/ETH_small.png').write_bytes(b'')` - rotkehlchen/tests/api/test_caching.py:45:10: FURB103 `open` and `write` should be replaced by `Path(f'{icons_dir}/BTC_small.png').write_bytes(b'')` - rotkehlchen/tests/api/test_caching.py:48:10: FURB103 `open` and `write` should be replaced by `Path(f'{icons_dir}/AVAX_small.png').write_bytes(b'')` ... 9 additional changes omitted for project
... Truncated remaining completed project reports due to GitHub comment length restrictions
Changes by rule (2 rules affected)
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| SIM103 | 194 | 97 | 97 | 0 | 0 |
| FURB103 | 140 | 0 | 140 | 0 | 0 |
Formatter (stable)
✅ ecosystem check detected no format changes.
Formatter (preview)
✅ ecosystem check detected no format changes.
## Summary This PR reviews the logic for IPython escape command parsing and makes the required changes to almost match the old parsing logic. ~One change I've not incorporated is the `unparse_expr`. The new parser can use `src_text` directly but this means that any whitespace is preserved~ Migrated the `unparse_expr` logic ## Test plan Use the new parser for testing escape commands and verify that there are no snapshot changes.
## Summary This PR reviews the logic for IPython escape command parsing and makes the required changes to almost match the old parsing logic. ~One change I've not incorporated is the `unparse_expr`. The new parser can use `src_text` directly but this means that any whitespace is preserved~ Migrated the `unparse_expr` logic ## Test plan Use the new parser for testing escape commands and verify that there are no snapshot changes.
## Summary This PR reviews the logic for IPython escape command parsing and makes the required changes to almost match the old parsing logic. ~One change I've not incorporated is the `unparse_expr`. The new parser can use `src_text` directly but this means that any whitespace is preserved~ Migrated the `unparse_expr` logic ## Test plan Use the new parser for testing escape commands and verify that there are no snapshot changes.
## Summary This PR reviews the logic for IPython escape command parsing and makes the required changes to almost match the old parsing logic. ~One change I've not incorporated is the `unparse_expr`. The new parser can use `src_text` directly but this means that any whitespace is preserved~ Migrated the `unparse_expr` logic ## Test plan Use the new parser for testing escape commands and verify that there are no snapshot changes.
## Summary This PR reviews the logic for IPython escape command parsing and makes the required changes to almost match the old parsing logic. ~One change I've not incorporated is the `unparse_expr`. The new parser can use `src_text` directly but this means that any whitespace is preserved~ Migrated the `unparse_expr` logic ## Test plan Use the new parser for testing escape commands and verify that there are no snapshot changes.
## Summary This PR reviews the logic for IPython escape command parsing and makes the required changes to almost match the old parsing logic. ~One change I've not incorporated is the `unparse_expr`. The new parser can use `src_text` directly but this means that any whitespace is preserved~ Migrated the `unparse_expr` logic ## Test plan Use the new parser for testing escape commands and verify that there are no snapshot changes.
Summary
This PR reviews the logic for IPython escape command parsing and makes the required changes to almost match the old parsing logic.
One change I've not incorporated is theMigrated theunparse_expr. The new parser can usesrc_textdirectly but this means that any whitespace is preservedunparse_exprlogicTest plan
Use the new parser for testing escape commands and verify that there are no snapshot changes.