Skip to content

Commit 6bc6199

Browse files
committed
Use PEP810!
1 parent 43e2633 commit 6bc6199

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

Lib/dataclasses.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import abc
99
from reprlib import recursive_repr
1010

11+
lazy import inspect
1112

1213
__all__ = ['dataclass',
1314
'field',
@@ -981,15 +982,12 @@ def _hash_exception(cls, fields, func_builder):
981982
# See https://bugs.python.org/issue32929#msg312829 for an if-statement
982983
# version of this table.
983984

984-
class AutoDocstring:
985-
"""A non-data descriptor to autogenerate class docstring
986-
from the signature of its __init__ method.
987-
"""
985+
# A non-data descriptor to autogenerate class docstring
986+
# from the signature of its __init__ method on demand.
987+
# The primary reason is to be able to lazy import `inspect` module.
988+
class _AutoDocstring:
988989

989990
def __get__(self, _obj, cls):
990-
# TODO: Make this top-level lazy import once PEP810 lands
991-
import inspect
992-
993991
try:
994992
# In some cases fetching a signature is not possible.
995993
# But, we surely should not fail in this case.
@@ -1237,7 +1235,7 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen,
12371235
if not getattr(cls, '__doc__'):
12381236
# Create a class doc-string lazily via descriptor protocol
12391237
# to avoid importing `inspect` module.
1240-
cls.__doc__ = AutoDocstring()
1238+
cls.__doc__ = _AutoDocstring()
12411239

12421240
if match_args:
12431241
# I could probably compute this once.
@@ -1392,8 +1390,6 @@ def _add_slots(cls, is_frozen, weakref_slot, defined_fields):
13921390

13931391
# If this is a wrapped function, unwrap it.
13941392
if not isinstance(member, type) and hasattr(member, '__wrapped__'):
1395-
# TODO: Make this top-level lazy import once PEP810 lands
1396-
import inspect
13971393
member = inspect.unwrap(member)
13981394

13991395
if isinstance(member, types.FunctionType):

0 commit comments

Comments
 (0)