Message407438
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. |
|
Date |
User |
Action |
Args |
2021-12-01 10:19:19 | Gobot1234 | set | recipients:
+ Gobot1234, eric.smith |
2021-12-01 10:19:19 | Gobot1234 | set | messageid: <1638353959.47.0.043888744355.issue45946@roundup.psfhosted.org> |
2021-12-01 10:19:19 | Gobot1234 | link | issue45946 messages |
2021-12-01 10:19:19 | Gobot1234 | create | |
|