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

[flake8-pyi] Implement PYI042 and PYI043 #4214

Merged
merged 5 commits into from
May 4, 2023

Conversation

arya-k
Copy link
Contributor

@arya-k arya-k commented May 3, 2023

PYI042 Type alias names should use CamelCase rather than snake_case
PYI043 Do not use names ending in "T" for private type aliases. (The "T" suffix implies that an object is a TypeVar.)

rel: #848

@arya-k arya-k marked this pull request as draft May 3, 2023 21:26
@github-actions
Copy link
Contributor

github-actions bot commented May 3, 2023

PR Check Results

Ecosystem

ℹ️ ecosystem check detected changes. (+12, -0, 0 error(s))

typeshed (+12, -0)

+ stdlib/typing.pyi:735:1: PYI042 Type alias `_get_type_hints_obj_allowed_types` should be CamelCase
+ stubs/cffi/_cffi_backend.pyi:113:5: PYI042 Type alias `buffer` should be CamelCase
+ stubs/cffi/cffi/api.pyi:13:1: PYI042 Type alias `basestring` should be CamelCase
+ stubs/cffi/cffi/api.pyi:18:5: PYI042 Type alias `buffer` should be CamelCase
+ stubs/pika/pika/spec.pyi:9:1: PYI042 Type alias `_str` should be CamelCase
+ stubs/pywin32/pythoncom.pyi:10:1: PYI042 Type alias `error` should be CamelCase
+ stubs/pywin32/win32/odbc.pyi:9:1: PYI042 Type alias `_odbcError` should be CamelCase
+ stubs/pywin32/win32comext/adsi/adsi.pyi:7:1: PYI042 Type alias `error` should be CamelCase
+ stubs/pywin32/win32comext/propsys/propsys.pyi:6:1: PYI042 Type alias `error` should be CamelCase
+ stubs/pywin32/win32comext/shell/shell.pyi:7:1: PYI042 Type alias `error` should be CamelCase
+ stubs/redis/redis/typing.pyi:17:1: PYI043 Private type alias `_StringLikeT` should not be suffixed with `T` (the `T` suffix implies that an object is a `TypeVar`)
+ stubs/requests/requests/compat.pyi:22:1: PYI042 Type alias `builtin_str` should be CamelCase

Benchmark

Linux

group                                      main                                   pr
-----                                      ----                                   --
linter/all-rules/large/dataset.py          1.01     17.1±0.09ms     2.4 MB/sec    1.00     16.9±0.06ms     2.4 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      4.1±0.01ms     4.1 MB/sec    1.00      4.1±0.01ms     4.1 MB/sec
linter/all-rules/numpy/globals.py          1.01    508.4±5.35µs     5.8 MB/sec    1.00    503.9±1.15µs     5.9 MB/sec
linter/all-rules/pydantic/types.py         1.00      7.0±0.03ms     3.6 MB/sec    1.00      7.0±0.04ms     3.6 MB/sec
linter/default-rules/large/dataset.py      1.00      8.3±0.02ms     4.9 MB/sec    1.01      8.4±0.02ms     4.9 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00   1778.6±6.09µs     9.4 MB/sec    1.01   1797.0±4.76µs     9.3 MB/sec
linter/default-rules/numpy/globals.py      1.00    199.2±2.15µs    14.8 MB/sec    1.02    202.3±4.97µs    14.6 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.7±0.01ms     6.9 MB/sec    1.01      3.7±0.06ms     6.8 MB/sec
parser/large/dataset.py                    1.00      6.6±0.02ms     6.2 MB/sec    1.00      6.6±0.01ms     6.2 MB/sec
parser/numpy/ctypeslib.py                  1.00   1275.4±1.81µs    13.1 MB/sec    1.00   1276.2±1.57µs    13.0 MB/sec
parser/numpy/globals.py                    1.00    129.8±0.50µs    22.7 MB/sec    1.00    130.1±0.33µs    22.7 MB/sec
parser/pydantic/types.py                   1.00      2.8±0.01ms     9.2 MB/sec    1.00      2.8±0.00ms     9.1 MB/sec

Windows

group                                      main                                   pr
-----                                      ----                                   --
linter/all-rules/large/dataset.py          1.02     17.0±0.20ms     2.4 MB/sec    1.00     16.6±0.07ms     2.5 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.02      4.3±0.04ms     3.8 MB/sec    1.00      4.2±0.02ms     3.9 MB/sec
linter/all-rules/numpy/globals.py          1.01    437.8±5.24µs     6.7 MB/sec    1.00    434.6±5.04µs     6.8 MB/sec
linter/all-rules/pydantic/types.py         1.01      7.2±0.04ms     3.5 MB/sec    1.00      7.1±0.04ms     3.6 MB/sec
linter/default-rules/large/dataset.py      1.02      8.7±0.03ms     4.7 MB/sec    1.00      8.5±0.04ms     4.8 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.02  1844.1±27.13µs     9.0 MB/sec    1.00  1803.8±13.18µs     9.2 MB/sec
linter/default-rules/numpy/globals.py      1.01    197.1±5.68µs    15.0 MB/sec    1.00    195.4±4.30µs    15.1 MB/sec
linter/default-rules/pydantic/types.py     1.01      3.9±0.03ms     6.5 MB/sec    1.00      3.9±0.04ms     6.5 MB/sec
parser/large/dataset.py                    1.00      6.8±0.03ms     6.0 MB/sec    1.00      6.8±0.02ms     6.0 MB/sec
parser/numpy/ctypeslib.py                  1.00   1295.2±7.08µs    12.9 MB/sec    1.00   1292.1±6.03µs    12.9 MB/sec
parser/numpy/globals.py                    1.01    134.9±1.42µs    21.9 MB/sec    1.00    133.6±1.01µs    22.1 MB/sec
parser/pydantic/types.py                   1.01      2.9±0.03ms     8.8 MB/sec    1.00      2.9±0.02ms     8.9 MB/sec

@arya-k
Copy link
Contributor Author

arya-k commented May 4, 2023

Hmm I'm not able to repro this test failure locally (macOS), when I run cargo test -p ruff_cli --test integration_test. I'm not quite sure what to make of this, and the CLI tests seem unrelated to my changes– do you have any tips @charliermarsh?

p.s. I'm pretty new to the ruff community: is it bad form to tag you like this?

@charliermarsh
Copy link
Member

@arya-k - Not sure why I can't repro locally either, but I have a suspicion that we just hit a factor-of-two boundary and need to increase the RuleSet bit vector size. In short, we have a vector that needs to be long enough to match the number of total rules, and we may have just exceeded the previous limit. I tried pushing a fix, lets see what happens.

Also: totally fine to tag me or other maintainers.

@arya-k arya-k marked this pull request as ready for review May 4, 2023 04:14
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution.

I think we should try to implement these rules without having to rely on regular expressions. Regular expressions are great but can be overkill when matching on simple patterns and using plain string methods can then be better for performance

@arya-k arya-k marked this pull request as draft May 4, 2023 14:57
@arya-k arya-k marked this pull request as ready for review May 4, 2023 16:35
@charliermarsh charliermarsh changed the title [flake8-pyi] PYI042, PYI043 [flake8-pyi] Implement PYI042 and PYI043 May 4, 2023
@charliermarsh charliermarsh added the rule Implementing or modifying a lint rule label May 4, 2023
@charliermarsh charliermarsh merged commit e9e194a into astral-sh:main May 4, 2023
14 checks passed
@arya-k
Copy link
Contributor Author

arya-k commented May 4, 2023

Thank you for pushing this over the finish line- for my understanding, how did you format the python files? My installation of black produced a much larger diff so I ignored it.

@charliermarsh
Copy link
Member

@arya-k - Oh interesting, I just ran Black from my own editor.

@charliermarsh
Copy link
Member

I should correct that: we probably haven't run Black over all of our Python fixtures, so running black from root could produce a large diff. I just ran Black over the new fixtures in this PR.

@arya-k
Copy link
Contributor Author

arya-k commented May 4, 2023

I should correct that: we probably haven't run Black over all of our Python fixtures, so running black from root could produce a large diff. I just ran Black over the new fixtures in this PR.

Ah got it. I ran it on all fixtures, then figured it wasn’t the way we were formatting python. Thanks for the clarification!

renovate bot added a commit to ixm-one/pytest-cmake-presets that referenced this pull request May 5, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [ruff](https://togithub.com/charliermarsh/ruff) | `^0.0.264` ->
`^0.0.265` |
[![age](https://badges.renovateapi.com/packages/pypi/ruff/0.0.265/age-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://badges.renovateapi.com/packages/pypi/ruff/0.0.265/adoption-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://badges.renovateapi.com/packages/pypi/ruff/0.0.265/compatibility-slim/0.0.264)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://badges.renovateapi.com/packages/pypi/ruff/0.0.265/confidence-slim/0.0.264)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>charliermarsh/ruff</summary>

###
[`v0.0.265`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.265)

[Compare
Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.264...v0.0.265)

<!-- Release notes generated using configuration in .github/release.yml
at main -->

#### What's Changed

##### Breaking Changes

- Change `--fix-only` exit semantics to mirror `--fix` by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#4146

##### Rules

- \[flake8-pyi] PYI020 by [@&#8203;arya-k](https://togithub.com/arya-k)
in
[astral-sh/ruff#4211
- Update B027 to support autofixing by
[@&#8203;aacunningham](https://togithub.com/aacunningham) in
[astral-sh/ruff#4178
- \[`flake8-pyi`] Implement `PYI042` and `PYI043` by
[@&#8203;arya-k](https://togithub.com/arya-k) in
[astral-sh/ruff#4214
- \[`pylint`] Implement import-self (`W0406`) by
[@&#8203;chanman3388](https://togithub.com/chanman3388) in
[astral-sh/ruff#4154
- Warn on PEP 604 syntax not in an annotation, but don't autofix by
[@&#8203;wookie184](https://togithub.com/wookie184) in
[astral-sh/ruff#4170

##### Bug Fixes

- Fix panic in pydocstyle D214 when docstring indentation is empty by
[@&#8203;madkinsz](https://togithub.com/madkinsz) in
[astral-sh/ruff#4216
- Render tabs as 4 spaces in diagnostics by
[@&#8203;MichaReiser](https://togithub.com/MichaReiser) in
[astral-sh/ruff#4132
- Fix era panic caused by out of bound edition by
[@&#8203;leiserfg](https://togithub.com/leiserfg) in
[astral-sh/ruff#4206
- End of statement insertion should occur after newline by
[@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) in
[astral-sh/ruff#4215
- Ignore **debuggerskip** in unused variable checks by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#4229

##### CLI

- Show settings path in `--show-settings` output by
[@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) in
[astral-sh/ruff#4199

##### Documentation

- Allow linking to individual rules by
[@&#8203;calumy](https://togithub.com/calumy) in
[astral-sh/ruff#4158

#### New Contributors

- [@&#8203;wookie184](https://togithub.com/wookie184) made their first
contribution in
[astral-sh/ruff#4170
- [@&#8203;arya-k](https://togithub.com/arya-k) made their first
contribution in
[astral-sh/ruff#4211

**Full Changelog**:
astral-sh/ruff@v0.0.264...v0.0.265

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://app.renovatebot.com/dashboard#github/ixm-one/pytest-cmake-presets).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS43MS40IiwidXBkYXRlZEluVmVyIjoiMzUuNzEuNCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Signed-off-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
renovate bot added a commit to allenporter/flux-local that referenced this pull request May 7, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [ruff](https://togithub.com/charliermarsh/ruff) | `==0.0.264` ->
`==0.0.265` |
[![age](https://badges.renovateapi.com/packages/pypi/ruff/0.0.265/age-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://badges.renovateapi.com/packages/pypi/ruff/0.0.265/adoption-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://badges.renovateapi.com/packages/pypi/ruff/0.0.265/compatibility-slim/0.0.264)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://badges.renovateapi.com/packages/pypi/ruff/0.0.265/confidence-slim/0.0.264)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>charliermarsh/ruff</summary>

###
[`v0.0.265`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.265)

[Compare
Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.264...v0.0.265)

<!-- Release notes generated using configuration in .github/release.yml
at main -->

#### What's Changed

##### Breaking Changes

- Change `--fix-only` exit semantics to mirror `--fix` by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#4146

##### Rules

- \[flake8-pyi] PYI020 by [@&#8203;arya-k](https://togithub.com/arya-k)
in
[astral-sh/ruff#4211
- Update B027 to support autofixing by
[@&#8203;aacunningham](https://togithub.com/aacunningham) in
[astral-sh/ruff#4178
- \[`flake8-pyi`] Implement `PYI042` and `PYI043` by
[@&#8203;arya-k](https://togithub.com/arya-k) in
[astral-sh/ruff#4214
- \[`pylint`] Implement import-self (`W0406`) by
[@&#8203;chanman3388](https://togithub.com/chanman3388) in
[astral-sh/ruff#4154
- Warn on PEP 604 syntax not in an annotation, but don't autofix by
[@&#8203;wookie184](https://togithub.com/wookie184) in
[astral-sh/ruff#4170

##### Bug Fixes

- Fix panic in pydocstyle D214 when docstring indentation is empty by
[@&#8203;madkinsz](https://togithub.com/madkinsz) in
[astral-sh/ruff#4216
- Render tabs as 4 spaces in diagnostics by
[@&#8203;MichaReiser](https://togithub.com/MichaReiser) in
[astral-sh/ruff#4132
- Fix era panic caused by out of bound edition by
[@&#8203;leiserfg](https://togithub.com/leiserfg) in
[astral-sh/ruff#4206
- End of statement insertion should occur after newline by
[@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) in
[astral-sh/ruff#4215
- Ignore **debuggerskip** in unused variable checks by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#4229

##### CLI

- Show settings path in `--show-settings` output by
[@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) in
[astral-sh/ruff#4199

##### Documentation

- Allow linking to individual rules by
[@&#8203;calumy](https://togithub.com/calumy) in
[astral-sh/ruff#4158

#### New Contributors

- [@&#8203;wookie184](https://togithub.com/wookie184) made their first
contribution in
[astral-sh/ruff#4170
- [@&#8203;arya-k](https://togithub.com/arya-k) made their first
contribution in
[astral-sh/ruff#4211

**Full Changelog**:
astral-sh/ruff@v0.0.264...v0.0.265

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://app.renovatebot.com/dashboard#github/allenporter/flux-local).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS43MS40IiwidXBkYXRlZEluVmVyIjoiMzUuNzEuNCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
renovate bot added a commit to allenporter/pyrainbird that referenced this pull request May 7, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [ruff](https://togithub.com/charliermarsh/ruff) | `==0.0.264` ->
`==0.0.265` |
[![age](https://badges.renovateapi.com/packages/pypi/ruff/0.0.265/age-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://badges.renovateapi.com/packages/pypi/ruff/0.0.265/adoption-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://badges.renovateapi.com/packages/pypi/ruff/0.0.265/compatibility-slim/0.0.264)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://badges.renovateapi.com/packages/pypi/ruff/0.0.265/confidence-slim/0.0.264)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>charliermarsh/ruff</summary>

###
[`v0.0.265`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.265)

[Compare
Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.264...v0.0.265)

<!-- Release notes generated using configuration in .github/release.yml
at main -->

#### What's Changed

##### Breaking Changes

- Change `--fix-only` exit semantics to mirror `--fix` by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#4146

##### Rules

- \[flake8-pyi] PYI020 by [@&#8203;arya-k](https://togithub.com/arya-k)
in
[astral-sh/ruff#4211
- Update B027 to support autofixing by
[@&#8203;aacunningham](https://togithub.com/aacunningham) in
[astral-sh/ruff#4178
- \[`flake8-pyi`] Implement `PYI042` and `PYI043` by
[@&#8203;arya-k](https://togithub.com/arya-k) in
[astral-sh/ruff#4214
- \[`pylint`] Implement import-self (`W0406`) by
[@&#8203;chanman3388](https://togithub.com/chanman3388) in
[astral-sh/ruff#4154
- Warn on PEP 604 syntax not in an annotation, but don't autofix by
[@&#8203;wookie184](https://togithub.com/wookie184) in
[astral-sh/ruff#4170

##### Bug Fixes

- Fix panic in pydocstyle D214 when docstring indentation is empty by
[@&#8203;madkinsz](https://togithub.com/madkinsz) in
[astral-sh/ruff#4216
- Render tabs as 4 spaces in diagnostics by
[@&#8203;MichaReiser](https://togithub.com/MichaReiser) in
[astral-sh/ruff#4132
- Fix era panic caused by out of bound edition by
[@&#8203;leiserfg](https://togithub.com/leiserfg) in
[astral-sh/ruff#4206
- End of statement insertion should occur after newline by
[@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) in
[astral-sh/ruff#4215
- Ignore **debuggerskip** in unused variable checks by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#4229

##### CLI

- Show settings path in `--show-settings` output by
[@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) in
[astral-sh/ruff#4199

##### Documentation

- Allow linking to individual rules by
[@&#8203;calumy](https://togithub.com/calumy) in
[astral-sh/ruff#4158

#### New Contributors

- [@&#8203;wookie184](https://togithub.com/wookie184) made their first
contribution in
[astral-sh/ruff#4170
- [@&#8203;arya-k](https://togithub.com/arya-k) made their first
contribution in
[astral-sh/ruff#4211

**Full Changelog**:
astral-sh/ruff@v0.0.264...v0.0.265

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://app.renovatebot.com/dashboard#github/allenporter/pyrainbird).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS43MS40IiwidXBkYXRlZEluVmVyIjoiMzUuNzEuNCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants