-
Notifications
You must be signed in to change notification settings - Fork 33
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
TYP: Type annotations overhaul, episode 2 #288
base: main
Are you sure you want to change the base?
Conversation
from typing import TYPE_CHECKING | ||
|
||
def get_xp(xp): | ||
__all__ = ["get_xp"] | ||
|
||
if TYPE_CHECKING: | ||
from collections.abc import Callable | ||
from types import ModuleType | ||
from typing import TypeVar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I much prefer avoiding if TYPE_CHECKING
blocks when possible, and use them only when necessary (circular imports and runtime support for obsolete versions of python).
The performance implications of importing from typing at runtime are absolutely negligible.
_T = TypeVar("_T") | ||
|
||
|
||
def get_xp(xp: "ModuleType") -> "Callable[[Callable[..., _T]], Callable[..., _T]]": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use bare annotations.
Where it would break things, because you either have a circular dependency or a if TYPE_CHECKING
block, please add from __future__ import annotations
to the top of the module.
from ._typing import Array, Device, DType, Namespace | ||
|
||
if TYPE_CHECKING: | ||
from typing_extensions import TypeIs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from typing_extensions import TypeIs | |
# TODO: import from typing (requires Python >=3.13) | |
from typing_extensions import TypeIs |
these comments make upgrading minimum python version so much easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea makes sense.
pyupgrade
(part of ruff) can also help a lot with that, fyi
I'm not really sure what's causing these test failures here 🤔 |
They're in main too |
This is a WIP in progress, but feel free to say whatever you feel like saying about the stuff I've already touched at this point.
_internal
common/*
numpy
__init__
_aliases
_info
_typing
fft
linalg
torch.*
dask.array.*
Because
cupy
has nopy.typed
, and is too dynamic for pyright to analyse, it's pretty much impossible to annotatecupy.*
at the moment.