Skip to content

Commit 3b89278

Browse files
committed
Refactor
Also, as we have many small _Repr instances, make the value a slot.
1 parent b04ad88 commit 3b89278

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

bpython/inspection.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@
3636
from .lazyre import LazyReCompile
3737

3838

39+
class _Repr:
40+
"""
41+
Helper for `ArgSpec`: Returns the given value in `__repr__()`.
42+
"""
43+
44+
__slots__ = ("value",)
45+
46+
def __init__(self, value: str) -> None:
47+
self.value = value
48+
49+
def __repr__(self) -> str:
50+
return self.value
51+
52+
__str__ = __repr__
53+
54+
3955
@dataclass
4056
class ArgSpec:
4157
args: List[str]
@@ -110,20 +126,6 @@ def __exit__(
110126
return False
111127

112128

113-
class _Repr:
114-
"""
115-
Helper for `fixlongargs()`: Returns the given value in `__repr__()`.
116-
"""
117-
118-
def __init__(self, value: str) -> None:
119-
self.value = value
120-
121-
def __repr__(self) -> str:
122-
return self.value
123-
124-
__str__ = __repr__
125-
126-
127129
def parsekeywordpairs(signature: str) -> Dict[str, str]:
128130
preamble = True
129131
stack = []
@@ -293,12 +295,15 @@ def _get_argspec_from_signature(f: Callable) -> ArgSpec:
293295
294296
"""
295297
args = []
296-
varargs = varkwargs = None
298+
varargs = None
299+
varkwargs = None
297300
defaults = []
298301
kwonly = []
299302
kwonly_defaults = {}
300303
annotations = {}
301304

305+
# We use signature here instead of getfullargspec as the latter also returns
306+
# self and cls (for class methods).
302307
signature = inspect.signature(f)
303308
for parameter in signature.parameters.values():
304309
if parameter.annotation is not parameter.empty:

0 commit comments

Comments
 (0)