Skip to content
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

Pyright reports an error with named axis #38

Open
Luceurre opened this issue Jul 27, 2022 · 2 comments
Open

Pyright reports an error with named axis #38

Luceurre opened this issue Jul 27, 2022 · 2 comments

Comments

@Luceurre
Copy link

Setup

  • pyright: 1.1.263
  • pytorch: 1.12.0+cu113
  • torchtyping: 0.1.4

Code Example

from torchtyping import TensorType

def example(foo: TensorType["batch"]):
    pass

Problem

Pyright reports the following error: "batch" is not defined

Related issue

The same error is reported by mypy when -1 is omitted: #35

@patrick-kidger
Copy link
Owner

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.

@wookayin
Copy link

wookayin commented Sep 3, 2022

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants