-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Feature request: make typing_modules
configurable
#11142
Comments
Hi, thanks for the issue! We already have a |
@AlexWaygood absolutely, thank you! I feel somewhat embarrassed since I remember asking a similar question before, but could not find it in my emails or otherwise (I now know it's #5400). I also searched the repository for I think the main reason why I went looking is because I checked https://docs.astral.sh/ruff/rules/typing-only-standard-library-import/ first, and the rule did not mention the configuration option. Maybe it should be added there (any in other |
The
typeguard
package enables run-time type checks. One of the drawbacks of run-time type checks is that type annotations behindif typing.TYPE_CHECKING
are not visible (https://typeguard.readthedocs.io/en/stable/userguide.html#notes-on-forward-reference-handling; compare also agronholm/typeguard#456).So this passes in
python bug.py
while it shouldn't (ideally):bug.py
One workaround that I am investigating is to use a project-local
typing_
module from which I import my ownTYPE_CHECKING
, like this:typing_.py
workaround.py
Then,
python workaround.py
fails as expected:but
A
is not used at runtime. Nice!(Obviously, my real
A
is more complicated than that, and my example above is too simplistic as it fails on lettingenable_runtime_typing_checks
returnFalse
- anyway, I guess this is enough to make the following main point.)When I apply this concept more generally, though:
code.py
ruff check --isolated --select=TCH003 code.py
gives me
So, long story short: can I make
ruff
understand my owntyping_.TYPE_CHECKING
as a type-checking block, similar totyping.TYPE_CHECKING
andtyping_extensions.TYPE_CHECKING
(compare #8429)?The text was updated successfully, but these errors were encountered: