New submission from Gobot1234 <gobot123...@gmail.com>:
Small snippet to reproduce: ``` from dataclasses import dataclass, field @dataclass class Foo: bool: bool = field() ``` Raises ``` --------------------------------------------------------------------------- RecursionError Traceback (most recent call last) <ipython-input-1-dce9c97e78ae> in <module> 2 3 @dataclass ----> 4 class Foo: 5 bool: bool = field() 6 /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/dataclasses.py in dataclass(cls, init, repr, eq, order, unsafe_hash, frozen, match_args, kw_only, slots) 1176 1177 # We're called as @dataclass without parens. -> 1178 return wrap(cls) 1179 1180 /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/dataclasses.py in wrap(cls) 1167 1168 def wrap(cls): -> 1169 return _process_class(cls, init, repr, eq, order, unsafe_hash, 1170 frozen, match_args, kw_only, slots) 1171 /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/dataclasses.py in _process_class(cls, init, repr, eq, order, unsafe_hash, frozen, match_args, kw_only, slots) 1085 # Create a class doc-string. 1086 cls.__doc__ = (cls.__name__ + -> 1087 str(inspect.signature(cls)).replace(' -> None', '')) 1088 1089 if match_args: /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/inspect.py in __str__(self) 3200 render_kw_only_separator = True 3201 for param in self.parameters.values(): -> 3202 formatted = str(param) 3203 3204 kind = param.kind /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/inspect.py in __str__(self) 2717 if self._annotation is not _empty: 2718 formatted = '{}: {}'.format(formatted, -> 2719 formatannotation(self._annotation)) 2720 2721 if self._default is not _empty: /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/inspect.py in formatannotation(annotation, base_module) 1362 return annotation.__qualname__ 1363 return annotation.__module__+'.'+annotation.__qualname__ -> 1364 return repr(annotation) 1365 1366 def formatannotationrelativeto(object): /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/dataclasses.py in __repr__(self) 281 282 def __repr__(self): --> 283 return ('Field(' 284 f'name={self.name!r},' 285 f'type={self.type!r},' ... last 1 frames repeated, from the frame below ... /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/dataclasses.py in __repr__(self) 281 282 def __repr__(self): --> 283 return ('Field(' 284 f'name={self.name!r},' 285 f'type={self.type!r},' RecursionError: maximum recursion depth exceeded while getting the repr of an object ``` This is due to the self.type being the field itself as the annotation is evaluated using the class namespace. ---------- components: Library (Lib) messages: 407438 nosy: Gobot1234, eric.smith priority: normal severity: normal status: open title: RecursionError when annotating a field with the same name as a field type: crash versions: Python 3.11 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue45946> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com