Closed bellini666 closed 2 years ago
Yeah, this won't work. Annotated
is a special form that requires a bunch of special-case logic to handle its peculiarities, and it can't be aliased like this. Sorry. You'll need to find some other approach if you want this to work with pyright.
There are some libs that uses a structure similar to
Annotated
to add extra runtime capabilities, while still being able to keep the variables properly typed.Strawberry is one of those libs. Since it uses the typing infrastructure for defining the graphql schema, it has a
LazyType
which can be used to avoid circular import issues but still be able to resolve the real type at runtime: https://github.com/strawberry-graphql/strawberry/blob/main/strawberry/lazy_type.pyI'm writing a patch for it where it would do something like this:
The idea here is that pyright would consider
LazyType
to be anAnnotated
and behave as such, but at runtime it can still do its lazy importing stuff.If I run pyright in that file I get this:
Which means that it is working as intended, but while aliased it is also trying to parse the second argument (and any other after the first) as a type if it is a string while it shouldn't (note that the issue didn't happen when I added
123
).