Commit Graph

339 Commits

Author SHA1 Message Date
InSync 4bec8ba731
[`flake8-bugbear`] Exempt `NewType` calls where the original type is immutable (`B008`) (#15765)
## Summary

Resolves #12717.

This change incorporates the logic added in #15588.

## Test Plan

`cargo nextest run` and `cargo insta test`.

---------

Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
2025-01-29 10:26:17 +00:00
Douglas Creager ef85c682bd
Remove customizable reference enum names (#15647)
The AST generator creates a reference enum for each syntax group — an
enum where each variant contains a reference to the relevant syntax
node. Previously you could customize the name of the reference enum for
a group — primarily because there was an existing `ExpressionRef` type
that wouldn't have lined up with the auto-derived name `ExprRef`. This
follow-up PR is a simple search/replace to switch over to the
auto-derived name, so that we can remove this customization point.
2025-01-21 13:46:31 -05:00
Dylan 4caeeb8d98
[`pylint`] Include name of base class in message for `redefined-slots-in-subclass` (`W0244`) (#15559)
In the following situation:

```python
class Grandparent:
  __slots__ = "a"

class Parent(Grandparent): ...

class Child(Parent):
  __slots__ = "a"
```

the message for `W0244` now specifies that `a` is overwriting a slot
from `Grandparent`.

To implement this, we introduce a helper function `iter_super_classes`
which does a breadth-first traversal of the superclasses of a given
class (as long as they are defined in the same file, due to the usual
limitations of the semantic model).

Note: Python does not allow conflicting slots definitions under multiple
inheritance. Unless I'm misunderstanding something, I believe It follows
that the subposet of superclasses of a given class that redefine a given
slot is in fact totally ordered. There is therefore a unique _nearest_
superclass whose slot is being overwritten. So, you know, in case anyone
was super worried about that... you can just chill.

This is a followup to #9640 .
2025-01-18 09:50:27 -06:00
Brent Westbrook e2da33a45c
[`unconventional-import-alias`] Fix infinite loop between ICN001 and I002 (`ICN001`) (#15480)
## Summary

This fixes the infinite loop reported in #14389 by raising an error to
the user about conflicting ICN001 (`unconventional-import-alias`) and
I002 (`missing-required-import`) configuration options.

## Test Plan

Added a CLI integration test reproducing the old behavior and then
confirming the fix.

Closes #14389

---------

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2025-01-16 10:45:24 -05:00
Garrett Reynolds dc491e8ade
[`ruff`] Fix false positive on global keyword (`RUF052`) (#15235) 2025-01-14 08:36:40 +01:00
Micha Reiser c39ca8fe6d
Upgrade Rust toolchain to 1.84.0 (#15408) 2025-01-11 09:51:58 +01:00
David Salvisberg 339167d372
[`flake8-type-checking`] Apply `TC008` more eagerly in `TYPE_CHECKING` blocks and disapply it in stubs (#15180)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2025-01-08 12:09:06 +00:00
Micha Reiser e4d9fe036a
Revert "Add all PEP-585 names to UP006 rule" (#15250) 2025-01-04 12:23:53 +01:00
InSync 6180f78da4
[`pyflakes`] Ignore errors in `@no_type_check` string annotations (`F722`, `F821`) (#15215) 2025-01-03 10:05:45 +01:00
David Salvisberg 1ef0f615f1
[`flake8-type-checking`] Improve flexibility of `runtime-evaluated-decorators` (#15204)
Co-authored-by: Micha Reiser <micha@reiser.io>
2024-12-31 16:28:10 +00:00
InSync 2a1aa29366
[`pylint`] Detect nested methods correctly (`PLW1641`) (#15032)
Co-authored-by: Micha Reiser <micha@reiser.io>
2024-12-30 16:55:14 +01:00
wookie184 04d538113a
Add all PEP-585 names to UP006 rule (#5454)
Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
Co-authored-by: dylwil3 <dylwil3@gmail.com>
Co-authored-by: Micha Reiser <micha@reiser.io>
2024-12-30 12:21:42 +01:00
InSync d4ee6abf4a
Visit PEP 764 inline `TypedDict`s' keys as non-type-expressions (#15073)
## Summary

Resolves #10812.

## Test Plan

`cargo nextest run` and `cargo insta test`.
2024-12-30 15:04:55 +05:30
Victorien 7ea3a549b2
Fix typo in `NameImport.qualified_name` docstring (#15170) 2024-12-28 23:44:01 +01:00
TomerBin 2fb6b320d8
Use TypeChecker for detecting fastapi routes (#15093) 2024-12-21 15:45:28 +01:00
David Salvisberg c0b7c36d43
[`ruff`] Avoid false positives for RUF027 for typing context bindings. (#15037)
Closes #14000 

## Summary

For typing context bindings we know that they won't be available at
runtime. We shouldn't recommend a fix, that will result in name errors
at runtime.

## Test Plan

`cargo nextest run`
2024-12-18 08:50:49 +01:00
InSync c62ba48ad4
[`ruff`] Do not simplify `round()` calls (`RUF046`) (#14832)
## Summary

Part 1 of the big change introduced in #14828. This temporarily causes
all fixes for `round(...)` to be considered unsafe, but they will
eventually be enhanced.

## Test Plan

`cargo nextest run` and `cargo insta test`.
2024-12-09 16:51:27 +01:00
InSync 0f4350e10e
Fix a typo in `class.rs` (#14877)
(Accidentally introduced in #14801.)
2024-12-09 15:36:42 +00:00
InSync aa6b812a73
[`flake8-pyi`] Also remove `self` and `cls`'s annotation (`PYI034`) (#14801)
Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
2024-12-09 14:59:12 +00:00
Thibaut Decombe 8d9e408dbb
Fix `PLW1508` false positive for default string created via a mult operation (#14841) 2024-12-08 18:25:47 +00:00
InSync 89368a62a8
[`flake8-use-pathlib`] Dotless suffix passed to `Path.with_suffix()` (`PTH901`) (#14779)
## Summary

Resolves #14441.

## Test Plan

`cargo nextest run` and `cargo insta test`.
2024-12-06 13:08:20 +01:00
Lokejoke bf0fd04e4e
[`ruff`] Implemented `used-dummy-variable` (`RUF052`) (#14611)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-12-03 08:36:16 +01:00
Micha Reiser f96dfc179f
Revert: [pyflakes] Avoid false positives in `@no_type_check` contexts (F821, F722) (#14615) (#14726) 2024-12-02 14:28:27 +01:00
Simon Brugman 48ec3a8add
[`refurb`] Guard `hashlib` imports and mark `hashlib-digest-hex` fix as safe (`FURB181`) (#14694)
## Summary

- Check if `hashlib` and `crypt` imports have been seen for `FURB181`
and `S324`
- Mark the fix for `FURB181` as safe: I think it was accidentally marked
as unsafe in the first place. The rule does not support user-defined
classes as the "fix safety" section suggests.
- Removed `hashlib._Hash`, as it's not part of the `hashlib` module.

<!-- What's the purpose of the change? What does it do, and why? -->

## Test Plan

Updated the test snapshots
2024-12-01 20:24:49 -05:00
Brent Westbrook 9e017634cb
[`pep8-naming`] Avoid false positive for `class Bar(type(foo))` (`N804`) (#14683) 2024-11-30 22:37:28 +00:00
Alex Waygood f3d8c023d3
[`ruff`] Avoid emitting `assignment-in-assert` when all references to the assigned variable are themselves inside `assert`s (`RUF018`) (#14661) 2024-11-29 13:36:59 +00:00
Micha Reiser b63c2e126b
Upgrade Rust toolchain to 1.83 (#14677) 2024-11-29 12:05:05 +00:00
Simon Brugman dc29f52750
[`flake8-pyi`, `ruff`] Fix traversal of nested literals and unions (`PYI016`, `PYI051`, `PYI055`, `PYI062`, `RUF041`) (#14641) 2024-11-28 18:07:12 +00:00
David Salvisberg 6d61c8aa16
Fixes minor bug in `SemanticModel::lookup_symbol` (#14643)
## Summary

This came up as part of #12927 when implementing
`SemanticModel::simulate_runtime_load`.

Should be fairly self-explanatory, if the scope returns a binding with
`BindingKind::Annotation` the bottom part of the loop gets skipped, so
there's no chance for `seen_function` to have been updated. So unless
there's something subtle going on here, like function scopes never
containing bindings with `BindingKind::Annotation`, this seems like a
bug.

## Test Plan

`cargo nextest run`
2024-11-27 16:50:19 -05:00
David Salvisberg 6fd10e2fe7
[`flake8-type-checking`] Adds implementation for TC007 and TC008 (#12927)
Co-authored-by: Simon Brugman <sbrugman@users.noreply.github.com>
Co-authored-by: Carl Meyer <carl@oddbird.net>
2024-11-27 09:51:20 +01:00
Brent Westbrook 9f446faa6c
[pyflakes] Avoid false positives in `@no_type_check` contexts (F821, F722) (#14615) 2024-11-26 19:13:43 +00:00
Tzu-ping Chung fbff4dec3a
[airflow] Avoid implicit DAG schedule (AIR301) (#14581) 2024-11-26 13:38:18 +01:00
Harutaka Kawamura e3d792605f
[`flake8-bugbear`] Fix `mutable-contextvar-default (B039)` to resolve annotated function calls properly (#14532)
## Summary

<!-- What's the purpose of the change? What does it do, and why? -->

Fix #14525

## Test Plan

<!-- How was it tested? -->

New test cases

---------

Signed-off-by: harupy <hkawamura0130@gmail.com>
2024-11-23 21:29:25 -05:00
InSync b9c53a74f9
[`pycodestyle`] Exempt `pytest.importorskip()` calls (`E402`) (#14474)
## Summary

Resolves #13537.

## Test Plan

`cargo nextest run` and `cargo insta test`.
2024-11-19 22:08:15 -05:00
InSync 5f09d4a90a
[`ruff`] `re` and `regex` calls with unraw string as first argument (`RUF039`) (#14446) 2024-11-19 13:44:55 +01:00
InSync d8b1afbc6e
[`ruff`] Also report problems for `attrs` dataclasses in preview mode (`RUF008`, `RUF009`) (#14327)
Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
2024-11-14 15:13:49 +00:00
Alex Waygood 78e4753d74
Remove unused flags and functions from the semantic model (#14318) 2024-11-13 17:35:48 +00:00
David Salvisberg 89aa804b2d
[flake8-type-checking] Fix false positives for `typing.Annotated` (#14311) 2024-11-13 12:17:52 +00:00
David Salvisberg f82ee8ea59
[flake8-markupsafe] Adds Implementation for MS001 via RUF035 (#14224)
Co-authored-by: Micha Reiser <micha@reiser.io>
2024-11-11 18:30:03 +00:00
Simon Brugman 84d4f114ef
Use bitshift consistently for bitflag definitions (#14265) 2024-11-11 10:20:17 +00:00
Harutaka Kawamura d4cf61d98b
Implement `shallow-copy-environ / W1507` (#14241)
<!--
Thank you for contributing to Ruff! To help us out with reviewing,
please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

<!-- What's the purpose of the change? What does it do, and why? -->

Related to #970. Implement [`shallow-copy-environ /
W1507`](https://pylint.readthedocs.io/en/stable/user_guide/messages/warning/shallow-copy-environ.html).

## Test Plan

<!-- How was it tested? -->

Unit test

---------

Co-authored-by: Simon Brugman <sbrugman@users.noreply.github.com>
Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2024-11-10 22:58:02 +00:00
Charlie Marsh 93fdf7ed36
Fix miscellaneous issues in `await-outside-async detection` (#14218)
## Summary

Closes https://github.com/astral-sh/ruff/issues/14167.
2024-11-08 21:07:13 -05:00
Micha Reiser 9f3a38d408
Extract `LineIndex` independent methods from `Locator` (#13938) 2024-10-28 07:53:41 +00:00
Alex Waygood 72adb09bf3
Simplify iteration idioms (#13834)
Remove unnecessary uses of `.as_ref()`, `.iter()`, `&**` and similar, mostly in situations when iterating over variables. Many of these changes are only possible following #13826, when we bumped our MSRV to 1.80: several useful implementations on `&Box<[T]>` were only stabilised in Rust 1.80. Some of these changes we could have done earlier, however.
2024-10-20 22:25:27 +01:00
Alex Waygood 5b4afd30ca
Harmonise methods for distinguishing different Python source types (#13682) 2024-10-09 13:18:52 +00:00
Zanie Blue d726f09cf0
Fix `PTH123` false positive when `open` is passed a file descriptor (#13616)
Closes https://github.com/astral-sh/ruff/issues/12871

Includes some minor semantic type inference extensions changes to help
with reliably detecting integers
2024-10-04 08:48:47 -05:00
Zanie Blue bbb044ebda
Detect tuples bound to variadic positional arguments i.e. `*args` (#13512)
In https://github.com/astral-sh/ruff/pull/13503, we added supported for
detecting variadic keyword arguments as dictionaries, here we use the
same strategy for detecting variadic positional arguments as tuples.
2024-09-25 10:03:25 -05:00
Zanie Blue 11f06e0d55
Detect SIM910 when using variadic keyword arguments, i.e., `**kwargs` (#13503)
Closes https://github.com/astral-sh/ruff/issues/13493
2024-09-25 10:02:59 -05:00
Alex Waygood 58c641c92f
Optimize some `SemanticModel` methods (#13091) 2024-09-02 10:03:52 +01:00
Charlie Marsh a73bebcf15
Avoid `no-self-use` for `attrs`-style validators (#13166)
## Summary

Closes https://github.com/astral-sh/ruff/issues/12568.
2024-08-30 12:39:05 -04:00