Replies: 1 comment
-
...heh. Fake annotations, huh? So this is what it's come to. I agree: you can't fix I also agree: I finally agree: @beartype should not complain about fake annotations. Sadly, @beartype currently complains about fake annotations and has no way of doing what you want. But @beartype should do what you want. But... how? A Modest Proposal: @beartype Eats All Your BugsKinda seems like @beartype should provide something to help you out here, doesn't it? I'm now thinking of a new beartype validator that forces @beartype to unconditionally ignore fake annotations: e.g., from beartype.vale import IsIgnorable # <-- this doesn't exist... *BUT IT COULD*
from typing import Annotated # <-- import this instead of "TYPE_CHECKING"
# Static type-checkers will still type-check this fake annotation,
# but @beartype no longer will. In theory, anyway. In practice,
# one wonders whether @leycec will ever implement this. He is lazy
# and known to play many video games instead of coding.
self.modules: Annotated[list[MyModule], IsIgnorable]] = nn.ModuleList(
[create_module_from_config(config) for config in configs]
) Would that satisfy your constraints, @avolchek? If so, let's promote this to a full-fledged feature request. |
Beta Was this translation helpful? Give feedback.
-
Hi!
Is there a way to exclude some of the local variable assignments from type checking? In my codebase, I have a bunch of annotations that don't pass the isinstance check. They are needed to force VSCode to think that the object is, in fact, of another type and to show autocomplete suggestions for that other type. For example, see pytorch/pytorch#80821. This issue is still unresolved, so I want to keep these fake annotations for a while, but I also want Beartype to not complain about it.
I could do the following:
but it looks cumbersome and leads to code duplication.
Beta Was this translation helpful? Give feedback.
All reactions