Skip to content

gh-105499: Defer "import warnings" in typing #132061

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

Merged
merged 1 commit into from
Apr 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import sys
import types
from types import GenericAlias
import warnings

from _typing import (
_idfunc,
Expand Down Expand Up @@ -1626,14 +1625,17 @@ def __getitem__(self, params):

class _UnionGenericAliasMeta(type):
def __instancecheck__(self, inst: object) -> bool:
import warnings
warnings._deprecated("_UnionGenericAlias", remove=(3, 17))
return isinstance(inst, Union)

def __subclasscheck__(self, inst: type) -> bool:
import warnings
warnings._deprecated("_UnionGenericAlias", remove=(3, 17))
return issubclass(inst, Union)

def __eq__(self, other):
import warnings
warnings._deprecated("_UnionGenericAlias", remove=(3, 17))
if other is _UnionGenericAlias or other is Union:
return True
Expand All @@ -1650,6 +1652,7 @@ class _UnionGenericAlias(metaclass=_UnionGenericAliasMeta):

"""
def __new__(cls, self_cls, parameters, /, *, name=None):
import warnings
warnings._deprecated("_UnionGenericAlias", remove=(3, 17))
return Union[parameters]

Expand Down
Loading