Skip to content

Commit d1db43c

Browse files
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.
1 parent 2009871 commit d1db43c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Lib/typing.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import sys
3131
import types
3232
from types import GenericAlias
33-
import warnings
3433

3534
from _typing import (
3635
_idfunc,
@@ -1626,14 +1625,17 @@ def __getitem__(self, params):
16261625

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

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

16361637
def __eq__(self, other):
1638+
import warnings
16371639
warnings._deprecated("_UnionGenericAlias", remove=(3, 17))
16381640
if other is _UnionGenericAlias or other is Union:
16391641
return True
@@ -1650,6 +1652,7 @@ class _UnionGenericAlias(metaclass=_UnionGenericAliasMeta):
16501652
16511653
"""
16521654
def __new__(cls, self_cls, parameters, /, *, name=None):
1655+
import warnings
16531656
warnings._deprecated("_UnionGenericAlias", remove=(3, 17))
16541657
return Union[parameters]
16551658

0 commit comments

Comments
 (0)