|
Is there a way to mark definitions to be ignored for the TC001 rule? With FastAPI I often have convenience definitions like this, which need to be evaluated at runtime for the OpenAPI docs and other things: PrincipalIdDep = Annotated[int, Depends(verify_auth)]I tried using the following setting: [tool.ruff.lint.flake8-type-checking]
runtime-evaluated-base-classes = ["mymodule.auth.PrincipalIdDep"]but I suspect because this isn't a base class it isn't recognized. Is there some other way to avoid adding If not, then I think a mark at the definition would be nicest to avoid repetition and disjointed and easily forgotten lists in some config. |
Replies: 3 comments 1 reply
|
I could be overlooking it, but I don't think there's currently a way to handle this. There was a previous discussion of a similar example in #13713, which was closed by improving our That issue also mentions a more general configuration option for runtime-evaluated annotations that might be relevant again, though. |
|
I think the problem is the import. I also have to apply |
|
Since Ruff currently does not support cross-file analysis to infer type information across module boundaries, metadata regarding runtime-evaluated classes like As a more scalable alternative to inline [tool.ruff.lint.per-file-ignores]
"**/dependencies.py" = ["TC001"]
"**/schemas/*.py" = ["TC001"]Additionally, for the specific case of runtime-evaluated-base-classes, ensure that the full qualified name is used if the inference is failing. If the type alias itself is causing the disruption, inlining the Annotated definition or using the global ignore pattern above remains the most efficient workaround until the proposed runtime-evaluated annotation configuration is implemented. |
Since Ruff currently does not support cross-file analysis to infer type information across module boundaries, metadata regarding runtime-evaluated classes like
pydantic.BaseModelis indeed lost during import. This is a known limitation of static analysis in the current architecture.As a more scalable alternative to inline
# noqa: TC001comments, you can utilize theper-file-ignoresconfiguration in yourpyproject.toml. This allows you to exclude specific modules or directories (such as dependency definitions or schemas) from theTC001rule without disabling it globally:Additionally, for the …