Open Luceurre opened 2 years ago
This is expected. Static type checking is (unfortunately) fundamentally incompatible with annotating arrays.
You should either add the appropriate flag to disable pyright's checking here, or define batch = None
elsewhere in the file so that pyright thinks this is a forward reference.
Can we use something like TypeVar
(instead of string literal for the type annotation) instead?
e.g.
Batch = typing.TypeVar
def example(foo: TensorType[Batch]):
pass
or
Batch = torchtyping.AxisVar("Batch") # a hypothetical API
def example(foo: TensorType[Batch]):
pass
UPDATE: seems relevant to #37 (PEP-646)
Setup
pyright
: 1.1.263pytorch
: 1.12.0+cu113torchtyping
: 0.1.4Code Example
Problem
Pyright reports the following error:
"batch" is not defined
Related issue
The same error is reported by mypy when
-1
is omitted: https://github.com/patrick-kidger/torchtyping/issues/35