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

A bunch of other warnings in typing.py were already deferred, but
I added a few non-lazy ones.
This commit is contained in:
Jelle Zijlstra 2025-04-04 06:19:42 -07:00 committed by GitHub
parent 20098719df
commit d1db43c139
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -30,7 +30,6 @@
import sys
import types
from types import GenericAlias
import warnings
from _typing import (
_idfunc,
@ -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
@ -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]