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

type warnings from pylance for image returned from pyexr.read() #34

Open
yellowtailfan opened this issue May 9, 2024 · 0 comments
Open

Comments

@yellowtailfan
Copy link

yellowtailfan commented May 9, 2024

When I use Numpy methods on an image returned from pyexr.read() then Pylance gives me a warning.

E.g. VS Code gives me a red squiggle on .shape on the last line of this code:

import pyexr
impath = 'image.exr'
im = pyexr.read(impath)
im.shape

The full warning from Pylance is:

Cannot access member "shape" for type "Dict[str, ndarray[Unknown, Unknown]]"
  Member "shape" is unknownPylance[reportAttributeAccessIssue](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportAttributeAccessIssue)

I saw that you recently added type hints, however the issue seems to be that read() can return either an image or a dict.

A work around is to add a cast() wrapper:

from typing import cast
import pyexr
from numpy import ndarray

impath = 'image.exr'
im = cast(ndarray, pyexr.read(impath))
im.shape

This code gives no warnings from Pylance.

Instead of casting, adding an assertion also works:

assert isinstance(im, ndarray)
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

1 participant