You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For runtime-typing, it is mentioned toSet to no if the app / libary does NOT need to support runtime introspection of type annotations. May I clarify what this means? I have from __future__ import annotations turned on throughout, but it does not seem to make a difference.
(Reason: I have Optional[str] usages and I realised that pylint only advises to turn them to str | None only if runtime-typing is a non-default no - I would have thought they should be turned to str | None as long as we have from __future__ import annotations)
Thanks for the question. The most common examples for runtime introspection are typing.get_type_hints and eval. Besides that there are libraries that use type annotations to generate code. If you rely on annotations just for type checking, you are probably fine.
However, just using the default (runtime-typing=yes) is definitely the safer option. I would even go as far as to say, only set it to no if you already know what it means.
I would have thought they should be turned to str | None as long as we have from future import annotations
My intention was to only suggest it when it's truly safe to do so as it is a stylistic choice anyway. Optional and Union haven't been deprecated. Someone might have added from __future__ import annotations to solve a forward reference or something else without realizing the actual impact.
Question
For
runtime-typing
, it is mentioned toSet to no if the app / libary does NOT need to support runtime introspection of type annotations
. May I clarify what this means? I havefrom __future__ import annotations
turned on throughout, but it does not seem to make a difference.(Reason: I have
Optional[str]
usages and I realised that pylint only advises to turn them tostr | None
only ifruntime-typing
is a non-defaultno
- I would have thought they should be turned tostr | None
as long as we havefrom __future__ import annotations
)Sidenote: minor typo here,
libary
->library
.The text was updated successfully, but these errors were encountered: