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

[pycodestyle]: Make blank lines in typing stub files optional (E3*) #10098

Merged
merged 1 commit into from
Mar 5, 2024

Conversation

MichaReiser
Copy link
Member

Summary

Fixes #10039

The recommendation for typing stub files is to use one blank line to group related definitions and
otherwise omit blank lines.

The newly added blank line rules (E3*) didn't account for typing stub files and enforced two empty lines at the top level and one empty line otherwise, making it impossible to group related definitions.

This PR implements the E3* rules to:

  • Not enforce blank lines. The use of blank lines in typing definitions is entirely up to the user.
  • Allow at most one empty line, including between top level statements.

Test Plan

Added unit tests (It may look odd that many snapshots are empty but the point is that the rule should no longer emit diagnostics)

@MichaReiser MichaReiser changed the base branch from main to blank-lines-isort February 23, 2024 15:12
@MichaReiser MichaReiser added bug Something isn't working preview Related to preview mode features labels Feb 23, 2024
Copy link
Contributor

github-actions bot commented Feb 23, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+57 -138 violations, +0 -0 fixes in 6 projects; 37 projects unchanged)

RasaHQ/rasa (+0 -4 violations, +0 -0 fixes)

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

- stubs/aio_pika/robust_channel.pyi:10:1: E302 [*] Expected 2 blank lines, found 1
- stubs/sanic.pyi:23:1: E302 [*] Expected 2 blank lines, found 1
- stubs/sanic.pyi:27:1: E302 [*] Expected 2 blank lines, found 1
- stubs/socketio.pyi:49:1: E302 [*] Expected 2 blank lines, found 1

apache/airflow (+0 -25 violations, +0 -0 fixes)

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

- airflow/compat/functools.pyi:27:1: E302 [*] Expected 2 blank lines, found 1
- airflow/decorators/__init__.pyi:102:5: E301 [*] Expected 1 blank line, found 0
- airflow/decorators/__init__.pyi:105:5: E301 [*] Expected 1 blank line, found 0
- airflow/decorators/__init__.pyi:158:5: E301 [*] Expected 1 blank line, found 0
- airflow/decorators/__init__.pyi:160:5: E301 [*] Expected 1 blank line, found 0
- airflow/decorators/__init__.pyi:191:5: E301 [*] Expected 1 blank line, found 0
- airflow/decorators/__init__.pyi:203:5: E301 [*] Expected 1 blank line, found 0
... 11 additional changes omitted for rule E301
- airflow/decorators/__init__.pyi:63:1: E302 [*] Expected 2 blank lines, found 1
- airflow/decorators/__init__.pyi:723:1: E305 [*] Expected 2 blank lines after class or function definition, found (1)
- airflow/utils/context.pyi:107:1: E302 [*] Expected 2 blank lines, found 1
... 15 additional changes omitted for project

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

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

- src/typings/IPython/core/getipython.pyi:3:1: E302 [*] Expected 2 blank lines, found 1
- src/typings/IPython/core/history.pyi:3:1: E302 [*] Expected 2 blank lines, found 1
- src/typings/IPython/core/interactiveshell.pyi:3:1: E302 [*] Expected 2 blank lines, found 1
- src/typings/IPython/display.pyi:3:1: E302 [*] Expected 2 blank lines, found 1
- src/typings/bs4.pyi:12:1: E302 [*] Expected 2 blank lines, found 1
- src/typings/bs4.pyi:15:1: E305 [*] Expected 2 blank lines after class or function definition, found (1)
- src/typings/bs4.pyi:17:1: E302 [*] Expected 2 blank lines, found 1
- src/typings/bs4.pyi:8:1: E302 [*] Expected 2 blank lines, found 1
... 46 additional changes omitted for rule E302
... 45 additional changes omitted for project

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

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

- redwood/redwood/__init__.pyi:6:1: E302 [*] Expected 2 blank lines, found 1

pandas-dev/pandas (+55 -55 violations, +0 -0 fixes)

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

- pandas/_libs/algos.pyi:101:5: PLR0917 Too many positional arguments (8/5)
+ pandas/_libs/algos.pyi:108:5: PLR0917 Too many positional arguments (7/5)
- pandas/_libs/algos.pyi:111:5: PLR0917 Too many positional arguments (7/5)
+ pandas/_libs/algos.pyi:15:7: PLW1641 Object does not implement `__hash__` method
- pandas/_libs/algos.pyi:17:7: PLW1641 Object does not implement `__hash__` method
+ pandas/_libs/algos.pyi:7:7: PLW1641 Object does not implement `__hash__` method
- pandas/_libs/algos.pyi:8:7: PLW1641 Object does not implement `__hash__` method
+ pandas/_libs/algos.pyi:98:5: PLR0917 Too many positional arguments (8/5)
- pandas/_libs/groupby.pyi:100:5: PLR0917 Too many positional arguments (8/5)
+ pandas/_libs/groupby.pyi:109:5: PLR0917 Too many positional arguments (7/5)
- pandas/_libs/groupby.pyi:110:5: PLR0917 Too many positional arguments (7/5)
+ pandas/_libs/groupby.pyi:118:5: PLR0917 Too many positional arguments (10/5)
- pandas/_libs/groupby.pyi:119:5: PLR0917 Too many positional arguments (10/5)
+ pandas/_libs/groupby.pyi:130:5: PLR0917 Too many positional arguments (9/5)
... 85 additional changes omitted for rule PLR0917
+ pandas/_libs/interval.pyi:54:1: PLR0904 Too many public methods (29 > 20)
- pandas/_libs/interval.pyi:58:1: PLR0904 Too many public methods (29 > 20)
+ pandas/_libs/tslibs/nattype.pyi:34:1: PLR0904 Too many public methods (63 > 20)
- pandas/_libs/tslibs/nattype.pyi:36:1: PLR0904 Too many public methods (63 > 20)
+ pandas/_libs/tslibs/offsets.pyi:34:1: PLR0904 Too many public methods (35 > 20)
- pandas/_libs/tslibs/offsets.pyi:36:1: PLR0904 Too many public methods (35 > 20)
+ pandas/_libs/tslibs/period.pyi:68:1: PLR0904 Too many public methods (24 > 20)
- pandas/_libs/tslibs/period.pyi:72:1: PLR0904 Too many public methods (24 > 20)
+ pandas/_libs/tslibs/timedeltas.pyi:95:1: PLR0904 Too many public methods (42 > 20)
- pandas/_libs/tslibs/timedeltas.pyi:97:1: PLR0904 Too many public methods (42 > 20)
... 3 additional changes omitted for rule PLR0904
... 86 additional changes omitted for project

rotki/rotki (+2 -0 violations, +0 -0 fixes)

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

+ stubs/Crypto/Random/__init__.pyi:11:1: E303 [*] Too many blank lines (2)
+ stubs/Crypto/Random/__init__.pyi:5:1: E303 [*] Too many blank lines (2)

Changes by rule (7 rules affected)

code total + violation - violation + fix - fix
PLR0917 94 47 47 0 0
E302 65 0 65 0 0
E301 16 0 16 0 0
PLR0904 12 6 6 0 0
PLW1641 4 2 2 0 0
E303 2 2 0 0 0
E305 2 0 2 0 0

@MichaReiser MichaReiser force-pushed the blank-lines-isort branch 2 times, most recently from 2fcdfbb to 066cc98 Compare March 1, 2024 15:53
@MichaReiser MichaReiser force-pushed the blank-lines-typing-stub branch 2 times, most recently from 3049521 to 1703c92 Compare March 1, 2024 16:25
@MichaReiser MichaReiser changed the title E3: Adjust expected blank lines for typing stub files [pycodestyle]: Make blank lines in typing stub files optional (E3*) Mar 1, 2024
Base automatically changed from blank-lines-isort to main March 5, 2024 10:09
@MichaReiser MichaReiser force-pushed the blank-lines-typing-stub branch 2 times, most recently from 6bf8c21 to e2c06ca Compare March 5, 2024 10:29
@MichaReiser MichaReiser merged commit af6ea2f into main Mar 5, 2024
17 checks passed
@MichaReiser MichaReiser deleted the blank-lines-typing-stub branch March 5, 2024 11:48
nkxxll pushed a commit to nkxxll/ruff that referenced this pull request Mar 10, 2024
…`) (astral-sh#10098)

## Summary

Fixes astral-sh#10039

The [recommendation for typing stub
files](https://typing.readthedocs.io/en/latest/source/stubs.html#blank-lines)
is to use **one** blank line to group related definitions and
otherwise omit blank lines. 

The newly added blank line rules (`E3*`) didn't account for typing stub
files and enforced two empty lines at the top level and one empty line
otherwise, making it impossible to group related definitions.

This PR implements the `E3*` rules to:

* Not enforce blank lines. The use of blank lines in typing definitions
is entirely up to the user.
* Allow at most one empty line, including between top level statements. 

## Test Plan

Added unit tests (It may look odd that many snapshots are empty but the
point is that the rule should no longer emit diagnostics)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working preview Related to preview mode features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

blank-line-between-methods (E301) & blank-lines-top-level (E302) - conflicts with formatter on .pyi files
2 participants