Skip to content

minor typing fixes in einops.py - #431

Open
jorenham wants to merge 1 commit into
arogozhnikov:mainfrom
jorenham:typing/einops/minor-fixes
Open

minor typing fixes in einops.py#431
jorenham wants to merge 1 commit into
arogozhnikov:mainfrom
jorenham:typing/einops/minor-fixes

Conversation

@jorenham

Copy link
Copy Markdown
Contributor

Note that TYPE_CHECKING is always False at runtime, so numpy will never actually be imported. This if TYPE_CHECKING just ensures that we can use the np.ndarray as static type annotation here, and avoid having to unnecessarily useAny (it's maximally type-unsafe).

I like the new TensorLike protocol. Before, it required that the __getitem__ parameter (arg) was actually named "arg". By changing it to a positional-only parameter, it will now allow any name. This doesn't mean that it's now required for types to also have a pos-only parameter for __getitem__, because of Barbara Liskov's substitution principle.

This also introduces a private _Axis type alias, which is used in several new annotations that resolve at least 4 mypy errors.

@arogozhnikov

Copy link
Copy Markdown
Owner

I'm working a patch that addresses these + a bit more, hopefully will get time over the weekend to finish

@jorenham

Copy link
Copy Markdown
Contributor Author

Ah even better. Feel free to ping me if you want me to give it a quick scan or somehting once you get there.

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

Successfully merging this pull request may close these issues.

2 participants