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

Avoid PYI015 for valid default value without annotation #4043

Merged

Conversation

dhruvmanila
Copy link
Member

Summary

As per the original implementation in flake8-pyi 1 2, we need to first check if the assignment value is valid.

Valid values are:

  • Type aliases
  • Type variable function calls
  • Union types (int | str)

Limitations:

This doesn't perform any type inference, so any variable or call would also be valid.

fixes: #4036

Footnotes

  1. https://github.com/PyCQA/flake8-pyi/blob/4d575338389bbf7b27fc2dac05e833c818388431/pyi.py#L1021

  2. https://github.com/PyCQA/flake8-pyi/blob/4d575338389bbf7b27fc2dac05e833c818388431/pyi.py#L832-L840

@dhruvmanila
Copy link
Member Author

dhruvmanila commented Apr 20, 2023

I'm not sure why the ecosystem checks failed to create a comment, but it can be seen here: https://github.com/charliermarsh/ruff/actions/runs/4753797743?pr=4043#summary-12893499356

@charliermarsh charliermarsh merged commit 7fd44a3 into astral-sh:main Apr 20, 2023
@charliermarsh
Copy link
Member

LGTM!

@charliermarsh charliermarsh added the bug Something isn't working label Apr 20, 2023
@dhruvmanila dhruvmanila deleted the fix/PYI015/default-value-in-assign branch April 23, 2023 10:00
renovate bot referenced this pull request in ixm-one/pytest-cmake-presets Apr 25, 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.262` ->
`^0.0.263` |
[![age](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/age-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/adoption-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/compatibility-slim/0.0.262)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/confidence-slim/0.0.262)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

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

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

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

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

#### What's Changed

##### Rules

- \[`flake8-bugbear`] Add `pytest.raises(Exception)` support to B017 by
[@&#8203;alanhdu](https://togithub.com/alanhdu) in
[https://github.com/charliermarsh/ruff/pull/4052](https://togithub.com/charliermarsh/ruff/pull/4052)
- \[`flake8-import-conventions`] Implement new rule `ICN003` to ban
`from ... import ...` for selected modules by
[@&#8203;edgarrmondragon](https://togithub.com/edgarrmondragon) in
[https://github.com/charliermarsh/ruff/pull/4040](https://togithub.com/charliermarsh/ruff/pull/4040)
- \[`pylint`] Implement PLE0302 `unexpected-special-method-signature` by
[@&#8203;mccullocht](https://togithub.com/mccullocht) in
[https://github.com/charliermarsh/ruff/pull/4075](https://togithub.com/charliermarsh/ruff/pull/4075)
- \[`pep8-naming`] Ignore `N815` for `TypedDict` fields by
[@&#8203;JonathanPlasse](https://togithub.com/JonathanPlasse) in
[https://github.com/charliermarsh/ruff/pull/4066](https://togithub.com/charliermarsh/ruff/pull/4066)

##### Bug Fixes

- Avoid `PYI015` for valid default value without annotation by
[@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) in
[https://github.com/charliermarsh/ruff/pull/4043](https://togithub.com/charliermarsh/ruff/pull/4043)
- Avoid infinite-propagation of inline comments when force-splitting
imports by [@&#8203;charliermarsh](https://togithub.com/charliermarsh)
in
[https://github.com/charliermarsh/ruff/pull/4074](https://togithub.com/charliermarsh/ruff/pull/4074)
- Fix SIM222 and SIM223 false positives and auto-fix by
[@&#8203;JonathanPlasse](https://togithub.com/JonathanPlasse) in
[https://github.com/charliermarsh/ruff/pull/4063](https://togithub.com/charliermarsh/ruff/pull/4063)
- Unify positional and keyword arguments when checking for missing
arguments in docstring by
[@&#8203;evanrittenhouse](https://togithub.com/evanrittenhouse) in
[https://github.com/charliermarsh/ruff/pull/4067](https://togithub.com/charliermarsh/ruff/pull/4067)
- Avoid `RUF008` if field annotation is immutable by
[@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) in
[https://github.com/charliermarsh/ruff/pull/4039](https://togithub.com/charliermarsh/ruff/pull/4039)
- Increment priority should be (branch-local, global) by
[@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) in
[https://github.com/charliermarsh/ruff/pull/4070](https://togithub.com/charliermarsh/ruff/pull/4070)
- Ignore `ClassVar` annotation for `RUF008`, `RUF009` by
[@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) in
[https://github.com/charliermarsh/ruff/pull/4081](https://togithub.com/charliermarsh/ruff/pull/4081)
- Support --fix in watch mode by
[@&#8203;evanrittenhouse](https://togithub.com/evanrittenhouse) in
[https://github.com/charliermarsh/ruff/pull/4035](https://togithub.com/charliermarsh/ruff/pull/4035)

#### New Contributors

- [@&#8203;alanhdu](https://togithub.com/alanhdu) made their first
contribution in
[https://github.com/charliermarsh/ruff/pull/4052](https://togithub.com/charliermarsh/ruff/pull/4052)
- [@&#8203;pronoym99](https://togithub.com/pronoym99) made their first
contribution in
[https://github.com/charliermarsh/ruff/pull/4055](https://togithub.com/charliermarsh/ruff/pull/4055)
- [@&#8203;Secrus](https://togithub.com/Secrus) made their first
contribution in
[https://github.com/charliermarsh/ruff/pull/4085](https://togithub.com/charliermarsh/ruff/pull/4085)
- [@&#8203;madkinsz](https://togithub.com/madkinsz) made their first
contribution in
[https://github.com/charliermarsh/ruff/pull/4084](https://togithub.com/charliermarsh/ruff/pull/4084)
- [@&#8203;mccullocht](https://togithub.com/mccullocht) made their first
contribution in
[https://github.com/charliermarsh/ruff/pull/4075](https://togithub.com/charliermarsh/ruff/pull/4075)

**Full Changelog**:
astral-sh/ruff@v0.0.262...v0.0.263

</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:eyJjcmVhdGVkSW5WZXIiOiIzNS41OC4yIiwidXBkYXRlZEluVmVyIjoiMzUuNTguMiJ9-->

Signed-off-by: Renovate Bot <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
renovate bot referenced this pull request in allenporter/flux-local Apr 27, 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.262` ->
`==0.0.263` |
[![age](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/age-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/adoption-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/compatibility-slim/0.0.262)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/confidence-slim/0.0.262)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

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

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

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

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

#### What's Changed

##### Rules

- \[`flake8-bugbear`] Add `pytest.raises(Exception)` support to B017 by
[@&#8203;alanhdu](https://togithub.com/alanhdu) in
[https://github.com/charliermarsh/ruff/pull/4052](https://togithub.com/charliermarsh/ruff/pull/4052)
- \[`flake8-import-conventions`] Implement new rule `ICN003` to ban
`from ... import ...` for selected modules by
[@&#8203;edgarrmondragon](https://togithub.com/edgarrmondragon) in
[https://github.com/charliermarsh/ruff/pull/4040](https://togithub.com/charliermarsh/ruff/pull/4040)
- \[`pylint`] Implement PLE0302 `unexpected-special-method-signature` by
[@&#8203;mccullocht](https://togithub.com/mccullocht) in
[https://github.com/charliermarsh/ruff/pull/4075](https://togithub.com/charliermarsh/ruff/pull/4075)
- \[`pep8-naming`] Ignore `N815` for `TypedDict` fields by
[@&#8203;JonathanPlasse](https://togithub.com/JonathanPlasse) in
[https://github.com/charliermarsh/ruff/pull/4066](https://togithub.com/charliermarsh/ruff/pull/4066)

##### Bug Fixes

- Avoid `PYI015` for valid default value without annotation by
[@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) in
[https://github.com/charliermarsh/ruff/pull/4043](https://togithub.com/charliermarsh/ruff/pull/4043)
- Avoid infinite-propagation of inline comments when force-splitting
imports by [@&#8203;charliermarsh](https://togithub.com/charliermarsh)
in
[https://github.com/charliermarsh/ruff/pull/4074](https://togithub.com/charliermarsh/ruff/pull/4074)
- Fix SIM222 and SIM223 false positives and auto-fix by
[@&#8203;JonathanPlasse](https://togithub.com/JonathanPlasse) in
[https://github.com/charliermarsh/ruff/pull/4063](https://togithub.com/charliermarsh/ruff/pull/4063)
- Unify positional and keyword arguments when checking for missing
arguments in docstring by
[@&#8203;evanrittenhouse](https://togithub.com/evanrittenhouse) in
[https://github.com/charliermarsh/ruff/pull/4067](https://togithub.com/charliermarsh/ruff/pull/4067)
- Avoid `RUF008` if field annotation is immutable by
[@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) in
[https://github.com/charliermarsh/ruff/pull/4039](https://togithub.com/charliermarsh/ruff/pull/4039)
- Increment priority should be (branch-local, global) by
[@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) in
[https://github.com/charliermarsh/ruff/pull/4070](https://togithub.com/charliermarsh/ruff/pull/4070)
- Ignore `ClassVar` annotation for `RUF008`, `RUF009` by
[@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) in
[https://github.com/charliermarsh/ruff/pull/4081](https://togithub.com/charliermarsh/ruff/pull/4081)
- Support --fix in watch mode by
[@&#8203;evanrittenhouse](https://togithub.com/evanrittenhouse) in
[https://github.com/charliermarsh/ruff/pull/4035](https://togithub.com/charliermarsh/ruff/pull/4035)

#### New Contributors

- [@&#8203;alanhdu](https://togithub.com/alanhdu) made their first
contribution in
[https://github.com/charliermarsh/ruff/pull/4052](https://togithub.com/charliermarsh/ruff/pull/4052)
- [@&#8203;pronoym99](https://togithub.com/pronoym99) made their first
contribution in
[https://github.com/charliermarsh/ruff/pull/4055](https://togithub.com/charliermarsh/ruff/pull/4055)
- [@&#8203;Secrus](https://togithub.com/Secrus) made their first
contribution in
[https://github.com/charliermarsh/ruff/pull/4085](https://togithub.com/charliermarsh/ruff/pull/4085)
- [@&#8203;madkinsz](https://togithub.com/madkinsz) made their first
contribution in
[https://github.com/charliermarsh/ruff/pull/4084](https://togithub.com/charliermarsh/ruff/pull/4084)
- [@&#8203;mccullocht](https://togithub.com/mccullocht) made their first
contribution in
[https://github.com/charliermarsh/ruff/pull/4075](https://togithub.com/charliermarsh/ruff/pull/4075)

**Full Changelog**:
astral-sh/ruff@v0.0.262...v0.0.263

</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:eyJjcmVhdGVkSW5WZXIiOiIzNS41OC4yIiwidXBkYXRlZEluVmVyIjoiMzUuNTguMiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
renovate bot referenced this pull request in allenporter/pyrainbird Apr 27, 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.262` ->
`==0.0.263` |
[![age](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/age-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/adoption-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/compatibility-slim/0.0.262)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/confidence-slim/0.0.262)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

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

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

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

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

##### What's Changed

##### Rules

- \[`flake8-bugbear`] Add `pytest.raises(Exception)` support to B017 by
[@&#8203;alanhdu](https://togithub.com/alanhdu) in
[https://github.com/charliermarsh/ruff/pull/4052](https://togithub.com/charliermarsh/ruff/pull/4052)
- \[`flake8-import-conventions`] Implement new rule `ICN003` to ban
`from ... import ...` for selected modules by
[@&#8203;edgarrmondragon](https://togithub.com/edgarrmondragon) in
[https://github.com/charliermarsh/ruff/pull/4040](https://togithub.com/charliermarsh/ruff/pull/4040)
- \[`pylint`] Implement PLE0302 `unexpected-special-method-signature` by
[@&#8203;mccullocht](https://togithub.com/mccullocht) in
[https://github.com/charliermarsh/ruff/pull/4075](https://togithub.com/charliermarsh/ruff/pull/4075)
- \[`pep8-naming`] Ignore `N815` for `TypedDict` fields by
[@&#8203;JonathanPlasse](https://togithub.com/JonathanPlasse) in
[https://github.com/charliermarsh/ruff/pull/4066](https://togithub.com/charliermarsh/ruff/pull/4066)

##### Bug Fixes

- Avoid `PYI015` for valid default value without annotation by
[@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) in
[https://github.com/charliermarsh/ruff/pull/4043](https://togithub.com/charliermarsh/ruff/pull/4043)
- Avoid infinite-propagation of inline comments when force-splitting
imports by [@&#8203;charliermarsh](https://togithub.com/charliermarsh)
in
[https://github.com/charliermarsh/ruff/pull/4074](https://togithub.com/charliermarsh/ruff/pull/4074)
- Fix SIM222 and SIM223 false positives and auto-fix by
[@&#8203;JonathanPlasse](https://togithub.com/JonathanPlasse) in
[https://github.com/charliermarsh/ruff/pull/4063](https://togithub.com/charliermarsh/ruff/pull/4063)
- Unify positional and keyword arguments when checking for missing
arguments in docstring by
[@&#8203;evanrittenhouse](https://togithub.com/evanrittenhouse) in
[https://github.com/charliermarsh/ruff/pull/4067](https://togithub.com/charliermarsh/ruff/pull/4067)
- Avoid `RUF008` if field annotation is immutable by
[@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) in
[https://github.com/charliermarsh/ruff/pull/4039](https://togithub.com/charliermarsh/ruff/pull/4039)
- Increment priority should be (branch-local, global) by
[@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) in
[https://github.com/charliermarsh/ruff/pull/4070](https://togithub.com/charliermarsh/ruff/pull/4070)
- Ignore `ClassVar` annotation for `RUF008`, `RUF009` by
[@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) in
[https://github.com/charliermarsh/ruff/pull/4081](https://togithub.com/charliermarsh/ruff/pull/4081)
- Support --fix in watch mode by
[@&#8203;evanrittenhouse](https://togithub.com/evanrittenhouse) in
[https://github.com/charliermarsh/ruff/pull/4035](https://togithub.com/charliermarsh/ruff/pull/4035)

##### New Contributors

- [@&#8203;alanhdu](https://togithub.com/alanhdu) made their first
contribution in
[https://github.com/charliermarsh/ruff/pull/4052](https://togithub.com/charliermarsh/ruff/pull/4052)
- [@&#8203;pronoym99](https://togithub.com/pronoym99) made their first
contribution in
[https://github.com/charliermarsh/ruff/pull/4055](https://togithub.com/charliermarsh/ruff/pull/4055)
- [@&#8203;Secrus](https://togithub.com/Secrus) made their first
contribution in
[https://github.com/charliermarsh/ruff/pull/4085](https://togithub.com/charliermarsh/ruff/pull/4085)
- [@&#8203;madkinsz](https://togithub.com/madkinsz) made their first
contribution in
[https://github.com/charliermarsh/ruff/pull/4084](https://togithub.com/charliermarsh/ruff/pull/4084)
- [@&#8203;mccullocht](https://togithub.com/mccullocht) made their first
contribution in
[https://github.com/charliermarsh/ruff/pull/4075](https://togithub.com/charliermarsh/ruff/pull/4075)

**Full Changelog**:
astral-sh/ruff@v0.0.262...v0.0.263

</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:eyJjcmVhdGVkSW5WZXIiOiIzNS41OC4yIiwidXBkYXRlZEluVmVyIjoiMzUuNTguMiJ9-->

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
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(🐞) False positive / bad fix for PYI015 with typealias in stub file
2 participants