ruff/crates/ruff_linter/resources/test/fixtures
Denys Kyslytsyn e677863787
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
[fastapi] Avoid false positive for class dependencies (FAST003) (#18271)
<!--
Thank you for contributing to Ruff/ty! 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? (Please prefix
with `[ty]` for ty pull
  requests.)
- Does this pull request include references to any relevant issues?
-->

## Summary

Closes #17226.

This PR updates the `FAST003` rule to correctly handle [FastAPI class
dependencies](https://fastapi.tiangolo.com/tutorial/dependencies/classes-as-dependencies/).
Specifically, if a path parameter is declared in either:

- a `pydantic.BaseModel` used as a dependency, or  
- the `__init__` method of a class used as a dependency,  

then `FAST003` will no longer incorrectly report it as unused.

FastAPI allows a shortcut when using annotated class dependencies -
`Depends` can be called without arguments, e.g.:

```python
class MyParams(BaseModel):
    my_id: int

@router.get("/{my_id}")
def get_id(params: Annotated[MyParams, Depends()]): ...
```
This PR ensures that such usage is properly supported by the linter.

Note: Support for dataclasses is not included in this PR. Let me know if
you’d like it to be added.

## Test Plan

Added relevant test cases to the `FAST003.py` fixture.
2025-06-02 14:34:50 -04:00
..
airflow [airflow] Add unsafe fix for module moved cases (AIR312) (#18363) 2025-05-30 09:36:20 -04:00
control-flow-graph
eradicate
fastapi [fastapi] Avoid false positive for class dependencies (FAST003) (#18271) 2025-06-02 14:34:50 -04:00
filesystem
flake8_2020
flake8_annotations
flake8_async [flake8_async] Refactor argument name resolution for async sleep func… (#18262) 2025-05-26 09:53:03 +00:00
flake8_bandit Implement template strings (#17851) 2025-05-30 15:00:56 -05:00
flake8_blind_except
flake8_boolean_trap
flake8_bugbear [flake8-bugbear] Ignore __debug__ attribute in B010 (#18357) 2025-05-28 16:24:52 -04:00
flake8_builtins [flake8-builtins] Ignore variables matching module attribute names (A001) (#16454) 2025-03-03 11:10:23 +01:00
flake8_commas
flake8_comprehensions [flake8-comprehensions]: Handle trailing comma in C403 fix (#16110) 2025-02-15 11:45:41 -06:00
flake8_datetimez [flake8-datetime] Ignore .replace() calls while looking for .astimezone (#16050) 2025-02-09 15:48:59 +00:00
flake8_debugger [flake8-debugger] Also flag sys.breakpointhook and sys.__breakpointhook__ (T100) (#16191) 2025-02-16 14:50:16 -05:00
flake8_django
flake8_errmsg
flake8_executable [flake8-executables] Allow uv run in shebang line for shebang-missing-python (EXE003) (#16849) 2025-03-19 10:35:07 -05:00
flake8_fixme
flake8_future_annotations
flake8_gettext
flake8_implicit_str_concat Add Autofix for ISC003 (#18256) 2025-05-28 09:30:51 +02:00
flake8_import_conventions [flake8-import-conventions] Add import numpy.typing as npt to default flake8-import-conventions.aliases (#17133) 2025-04-02 09:25:46 +02:00
flake8_logging [flake8-logging] .exception() and exc_info= outside exception handlers (LOG004, LOG014) (#15799) 2025-02-04 09:52:12 +01:00
flake8_logging_format
flake8_no_pep420
flake8_pie [flake8-pie] Mark autofix for PIE804 as unsafe if the dictionary contains comments (#18046) 2025-05-12 10:16:59 -05:00
flake8_print
flake8_pyi Implement template strings (#17851) 2025-05-30 15:00:56 -05:00
flake8_pytest_style [flake8-pytest-style] Don't recommend usefixtures for parametrize values in PT019 (#17650) 2025-05-14 10:31:42 -04:00
flake8_quotes Implement template strings (#17851) 2025-05-30 15:00:56 -05:00
flake8_raise
flake8_return
flake8_self [flake8-self] Ignore attribute accesses on instance-like variables (SLF001) (#16149) 2025-02-23 10:00:49 +00:00
flake8_simplify [flake8-simplify] Correct behavior for str.split/rsplit with maxsplit=0 (SIM905) (#18075) 2025-05-14 14:20:18 -04:00
flake8_slots
flake8_tidy_imports
flake8_todos [flake8-todos] Allow VSCode GitHub PR extension style links in missing-todo-link (TD003) (#15519) 2025-01-15 23:47:33 +00:00
flake8_type_checking Fixes how the checker visits typing.cast/typing.NewType arguments (#17538) 2025-04-23 09:26:00 +02:00
flake8_unused_arguments Consider __new__ methods as special function type for enforcing class method or static method rules (#13305) 2025-02-16 14:12:25 -06:00
flake8_use_pathlib [flake8_use_pathlib]: Replace os.symlink with Path.symlink_to (PTH211) (#18337) 2025-05-28 12:39:05 +02:00
flynt
isort
mccabe
numpy
pandas_vet
pep8_naming [pep8-naming] Consider any number of leading underscore for N801 (#15988) 2025-02-06 14:08:27 +05:30
perflint Fix typos (#17988) 2025-05-09 14:57:14 -04:00
pycodestyle Implement template strings (#17851) 2025-05-30 15:00:56 -05:00
pydoclint
pydocstyle [pydocstyle] Handle arguments with the same names as sections (D417) (#16011) 2025-02-11 12:05:29 -05:00
pyflakes [ty] Don't warn yield not in function when yield is in function (#18008) 2025-05-21 18:16:25 +02:00
pygrep_hooks
pylint [pylint] Implement missing-maxsplit-arg (PLC0207) (#17454) 2025-05-28 20:46:30 +00:00
pyupgrade [pyupgrade]: new rule UP050 (useless-class-metaclass-type) (#18334) 2025-05-28 09:22:44 +02:00
refurb [refurb] Add coverage of set and frozenset calls (FURB171) (#18035) 2025-05-29 14:59:49 -04:00
ruff [ruff] Implement a recursive check for RUF060 (#17976) 2025-05-12 16:17:13 -04:00
syntax_errors [semantic-syntax-tests] Add test fixtures for AwaitOutsideAsyncFunction (#17785) 2025-05-05 14:02:06 -04:00
tryceratops
__init__.py