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

Disallow dotted name in from ... import statement #10903

Merged
merged 1 commit into from
Apr 12, 2024

Conversation

dhruvmanila
Copy link
Member

Summary

Dotted names aren't allowed in from ... import statement. They're only allowed in import statement.

Alternative

Another solution would be to parse the dotted name, check if there's a . in the parsed string and raise an error.

I choose not to do this because it didn't make sense to do contains for every import name.

Test Plan

Add invalid syntax test cases to verify the logic.

@dhruvmanila dhruvmanila added bug Something isn't working parser Related to the parser fuzzer Surfaced via fuzzing. labels Apr 12, 2024
@dhruvmanila dhruvmanila merged commit cefa753 into dhruv/parser Apr 12, 2024
17 checks passed
@dhruvmanila dhruvmanila deleted the dhruv/from-import-dot-name branch April 12, 2024 08:35
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+58 -569 violations, +0 -0 fixes in 14 projects; 30 projects unchanged)

aiven/aiven-client (+0 -1 violations, +0 -0 fixes)

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

- aiven/client/client.py:159:9: PLR6104 Use `+=` to perform an augmented assignment directly

PlasmaPy/PlasmaPy (+3 -35 violations, +0 -0 fixes)

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

- plasmapy/analysis/tests/test_fit_functions.py:241:13: PLR6104 Use `*=` to perform an augmented assignment directly
- plasmapy/analysis/tests/test_fit_functions.py:263:13: PLR6104 Use `*=` to perform an augmented assignment directly
- plasmapy/analysis/time_series/running_moments.py:61:5: PLR6104 Use `-=` to perform an augmented assignment directly
- plasmapy/diagnostics/charged_particle_radiography/synthetic_radiography.py:413:13: PLR6104 Use `/=` to perform an augmented assignment directly
- plasmapy/diagnostics/charged_particle_radiography/synthetic_radiography.py:419:13: PLR6104 Use `/=` to perform an augmented assignment directly
- plasmapy/diagnostics/charged_particle_radiography/synthetic_radiography.py:830:9: PLR6104 Use `+=` to perform an augmented assignment directly
... 27 additional changes omitted for rule PLR6104
+ plasmapy/formulary/collisions/helio/collisional_analysis.py:238:9: PLR0917 Too many positional arguments (12/5)
- plasmapy/formulary/collisions/helio/collisional_analysis.py:238:9: PLR0917 Too many positional arguments (12/5)
+ plasmapy/particles/ionization_state.py:705:12: PLW0117 Comparing against a NaN value; use `np.isnan` instead
- plasmapy/particles/ionization_state.py:705:12: PLW0177 Comparing against a NaN value; use `np.isnan` instead
... 28 additional changes omitted for project

apache/airflow (+3 -52 violations, +0 -0 fixes)

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

- airflow/cli/commands/kubernetes_command.py:84:5: PLR1730 [*] Replace `if` statement with `min_pending_minutes = max(min_pending_minutes, 5)`
+ airflow/cli/commands/kubernetes_command.py:84:5: PLR1730 [*] Replace `if` statement with `min_pending_minutes = min(min_pending_minutes, 5)`
- airflow/io/path.py:252:13: PLR6104 Use `/=` to perform an augmented assignment directly
- airflow/io/path.py:254:13: PLR6104 Use `/=` to perform an augmented assignment directly
- airflow/kubernetes/pre_7_4_0_compatibility/kube_client.py:89:5: PLR6104 Use `+=` to perform an augmented assignment directly
- airflow/kubernetes/pre_7_4_0_compatibility/kube_client.py:90:5: PLR6104 Use `+=` to perform an augmented assignment directly
- airflow/models/taskinstance.py:1635:21: PLR6104 Use `/=` to perform an augmented assignment directly
- airflow/models/taskinstance.py:2171:13: PLR1730 [*] Replace `if` statement with `min_backoff = max(min_backoff, 1)`
+ airflow/models/taskinstance.py:2171:13: PLR1730 [*] Replace `if` statement with `min_backoff = min(min_backoff, 1)`
- airflow/models/taskinstance.py:3758:17: B909 Mutation to loop iterable `new_dict` during iteration
... 45 additional changes omitted for project

aws/aws-sam-cli (+0 -128 violations, +0 -0 fixes)

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

- samcli/commands/_utils/table_print.py:46:9: PLR6104 Use `-=` to perform an augmented assignment directly
- samcli/commands/init/interactive_event_bridge_flow.py:174:9: PLR6104 Use `+=` to perform an augmented assignment directly
- samcli/lib/build/bundler.py:178:13: PLR6104 Use `+=` to perform an augmented assignment directly
- samcli/lib/deploy/deployer.py:468:17: PLR6104 Use `+=` to perform an augmented assignment directly
- samcli/lib/deploy/deployer.py:814:13: PLR6104 Use `+=` to perform an augmented assignment directly
- samcli/lib/schemas/cli_paginator.py:27:9: PLR6104 Use `+=` to perform an augmented assignment directly
- samcli/lib/schemas/cli_paginator.py:34:9: PLR6104 Use `+=` to perform an augmented assignment directly
- samcli/lib/schemas/cli_paginator.py:38:9: PLR6104 Use `+=` to perform an augmented assignment directly
- samcli/lib/schemas/cli_paginator.py:42:9: PLR6104 Use `+=` to perform an augmented assignment directly
- samcli/lib/schemas/cli_paginator.py:59:9: PLR6104 Use `-=` to perform an augmented assignment directly
... 118 additional changes omitted for project

bokeh/bokeh (+0 -6 violations, +0 -0 fixes)

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

- src/bokeh/embed/server.py:294:9: PLR6104 Use `+=` to perform an augmented assignment directly
- src/bokeh/resources.py:379:13: PLR6104 Use `+=` to perform an augmented assignment directly
- src/bokeh/server/tornado.py:307:13: PLR6104 Use `+=` to perform an augmented assignment directly
- src/bokeh/server/tornado.py:422:17: PLR6104 Use `+=` to perform an augmented assignment directly
- src/bokeh/server/util.py:96:9: PLR6104 Use `+=` to perform an augmented assignment directly
- src/bokeh/util/token.py:308:9: PLR6104 Use `+=` to perform an augmented assignment directly

freedomofpress/securedrop (+0 -2 violations, +0 -0 fixes)

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

- securedrop/pretty_bad_protocol/_util.py:462:5: PLR6104 Use `%=` to perform an augmented assignment directly
- securedrop/tests/test_journalist.py:1864:9: PLR6104 Use `+=` to perform an augmented assignment directly

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

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

- ibis/backends/bigquery/tests/unit/udf/test_usage.py:25:5: PLR6104 Use `+=` to perform an augmented assignment directly
- ibis/backends/druid/__init__.py:61:9: PLR6104 Use `|=` to perform an augmented assignment directly
- ibis/backends/exasol/__init__.py:100:9: PLR6104 Use `|=` to perform an augmented assignment directly
- ibis/backends/pandas/executor.py:630:17: PLR6104 Use `&=` to perform an augmented assignment directly
- ibis/common/annotations.py:287:13: PLR6104 Use `+=` to perform an augmented assignment directly
- ibis/common/annotations.py:289:13: PLR6104 Use `+=` to perform an augmented assignment directly
- ibis/common/tests/test_numeric.py:63:13: PLR6104 Use `+=` to perform an augmented assignment directly
- ibis/common/tests/test_numeric.py:68:13: PLR6104 Use `+=` to perform an augmented assignment directly
- ibis/common/tests/test_numeric.py:75:13: PLR6104 Use `+=` to perform an augmented assignment directly
- ibis/expr/tests/test_api.py:156:9: PLR6104 Use `+=` to perform an augmented assignment directly

milvus-io/pymilvus (+3 -33 violations, +0 -0 fixes)

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

- examples/example_bulkinsert_json.py:142:9: PLR6104 Use `+=` to perform an augmented assignment directly
- examples/example_bulkinsert_json.py:224:13: PLR6104 Use `+=` to perform an augmented assignment directly
- examples/example_bulkinsert_json.py:247:13: PLR6104 Use `+=` to perform an augmented assignment directly
- examples/example_bulkinsert_json.py:249:13: PLR6104 Use `+=` to perform an augmented assignment directly
- examples/example_bulkinsert_json.py:251:13: PLR6104 Use `+=` to perform an augmented assignment directly
- examples/example_bulkinsert_json.py:253:13: PLR6104 Use `+=` to perform an augmented assignment directly
... 25 additional changes omitted for rule PLR6104
- pymilvus/bulk_writer/buffer.py:240:13: PLR1730 [*] Replace `if` statement with `max` call
+ pymilvus/bulk_writer/buffer.py:240:13: PLR1730 [*] Replace `if` statement with `min` call
+ pymilvus/bulk_writer/buffer.py:242:13: PLR1730 [*] Replace `if` statement with `max` call
- pymilvus/bulk_writer/buffer.py:242:13: PLR1730 [*] Replace `if` statement with `min` call
... 26 additional changes omitted for project

pandas-dev/pandas (+48 -179 violations, +0 -0 fixes)

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

- asv_bench/benchmarks/algos/isin.py:136:13: PLR6104 Use `+=` to perform an augmented assignment directly
- asv_bench/benchmarks/arithmetic.py:141:13: PLR6104 Use `//=` to perform an augmented assignment directly
- pandas/_testing/contexts.py:113:5: PLR6104 Use `+=` to perform an augmented assignment directly
- pandas/compat/numpy/function.py:107:9: PLR6104 Use `+=` to perform an augmented assignment directly
- pandas/compat/numpy/function.py:168:9: PLR6104 Use `+=` to perform an augmented assignment directly
- pandas/compat/numpy/function.py:200:9: PLR6104 Use `+=` to perform an augmented assignment directly
- pandas/compat/numpy/function.py:229:9: PLR6104 Use `+=` to perform an augmented assignment directly
... 125 additional changes omitted for rule PLR6104
+ pandas/core/arrays/arrow/array.py:1403:29: PLW0117 Comparing against a NaN value; use `np.isnan` instead
- pandas/core/arrays/arrow/array.py:1403:29: PLW0177 Comparing against a NaN value; use `np.isnan` instead
+ pandas/core/arrays/categorical.py:1563:82: PLW0117 Comparing against a NaN value; use `np.isnan` instead
- pandas/core/arrays/categorical.py:1563:82: PLW0177 Comparing against a NaN value; use `np.isnan` instead
+ pandas/core/arrays/string_arrow.py:710:20: PLW0117 Comparing against a NaN value; use `np.isnan` instead
- pandas/core/arrays/string_arrow.py:710:20: PLW0177 Comparing against a NaN value; use `np.isnan` instead
+ pandas/core/base.py:639:34: PLW0117 Comparing against a NaN value; use `np.isnan` instead
- pandas/core/base.py:639:34: PLW0177 Comparing against a NaN value; use `np.isnan` instead
+ pandas/core/internals/managers.py:1000:48: PLW0117 Comparing against a NaN value; use `np.isnan` instead
- pandas/core/internals/managers.py:1000:48: PLW0177 Comparing against a NaN value; use `np.isnan` instead
+ pandas/core/strings/accessor.py:347:63: PLW0117 Comparing against a NaN value; use `np.isnan` instead
... 209 additional changes omitted for project

python/mypy (+0 -1 violations, +0 -0 fixes)

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

- mypy/build.py:3200:21: B909 Mutation to loop iterable `new` during iteration

... Truncated remaining completed project reports due to GitHub comment length restrictions

Changes by rule (6 rules affected)

code total + violation - violation + fix - fix
PLR6104 506 0 506 0 0
PLW0117 50 50 0 0 0
PLW0177 50 0 50 0 0
PLR1730 14 7 7 0 0
B909 5 0 5 0 0
PLR0917 2 1 1 0 0

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

dhruvmanila added a commit that referenced this pull request Apr 15, 2024
## Summary

Dotted names aren't allowed in `from ... import` statement. They're only
allowed in `import` statement.

### Alternative

Another solution would be to parse the dotted name, check if there's a
`.` in the parsed string and raise an error.

I choose not to do this because it didn't make sense to do `contains`
for every import name.

## Test Plan

Add invalid syntax test cases to verify the logic.
dhruvmanila added a commit that referenced this pull request Apr 16, 2024
## Summary

Dotted names aren't allowed in `from ... import` statement. They're only
allowed in `import` statement.

### Alternative

Another solution would be to parse the dotted name, check if there's a
`.` in the parsed string and raise an error.

I choose not to do this because it didn't make sense to do `contains`
for every import name.

## Test Plan

Add invalid syntax test cases to verify the logic.
dhruvmanila added a commit that referenced this pull request Apr 16, 2024
## Summary

Dotted names aren't allowed in `from ... import` statement. They're only
allowed in `import` statement.

### Alternative

Another solution would be to parse the dotted name, check if there's a
`.` in the parsed string and raise an error.

I choose not to do this because it didn't make sense to do `contains`
for every import name.

## Test Plan

Add invalid syntax test cases to verify the logic.
dhruvmanila added a commit that referenced this pull request Apr 17, 2024
## Summary

Dotted names aren't allowed in `from ... import` statement. They're only
allowed in `import` statement.

### Alternative

Another solution would be to parse the dotted name, check if there's a
`.` in the parsed string and raise an error.

I choose not to do this because it didn't make sense to do `contains`
for every import name.

## Test Plan

Add invalid syntax test cases to verify the logic.
dhruvmanila added a commit that referenced this pull request Apr 18, 2024
## Summary

Dotted names aren't allowed in `from ... import` statement. They're only
allowed in `import` statement.

### Alternative

Another solution would be to parse the dotted name, check if there's a
`.` in the parsed string and raise an error.

I choose not to do this because it didn't make sense to do `contains`
for every import name.

## Test Plan

Add invalid syntax test cases to verify the logic.
dhruvmanila added a commit that referenced this pull request Apr 18, 2024
(Supersedes #9152, authored by @LaBatata101)

## Summary

This PR replaces the current parser generated from LALRPOP to a
hand-written recursive descent parser.

It also updates the grammar for [PEP
646](https://peps.python.org/pep-0646/) so that the parser outputs the
correct AST. For example, in `data[*x]`, the index expression is now a
tuple with a single starred expression instead of just a starred
expression.

Beyond the performance improvements, the parser is also error resilient
and can provide better error messages. The behavior as seen by any
downstream tools isn't changed. That is, the linter and formatter can
still assume that the parser will _stop_ at the first syntax error. This
will be updated in the following months.

For more details about the change here, refer to the PR corresponding to
the individual commits and the release blog post.

## Test Plan

Write _lots_ and _lots_ of tests for both valid and invalid syntax and
verify the output.

## Acknowledgements

- @MichaReiser for reviewing 100+ parser PRs and continuously providing
guidance throughout the project
- @LaBatata101 for initiating the transition to a hand-written parser in
#9152
- @addisoncrump for implementing the fuzzer which helped
[catch](#10903)
[a](#10910)
[lot](#10966)
[of](#10896)
[bugs](#10877)

---------

Co-authored-by: Victor Hugo Gomes <labatata101@linuxmail.org>
Co-authored-by: Micha Reiser <micha@reiser.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fuzzer Surfaced via fuzzing. parser Related to the parser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants