Message 339811 - Python tracker

Message339811

Author eric.smith
Recipients John Parejko2, eric.smith
Date 2019-04-09.21:56:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1554847004.7.0.258028026707.issue36580@roundup.psfhosted.org>
In-reply-to
Content
I'm not sure why dataclasses would be different here:

>>> import dataclasses
>>> import unittest.mock
>>> @dataclasses.dataclass
... class Foo:
...     name: str
...     baz: float
...     bar: int = 12
...
>>> import inspect
>>> inspect.signature(Foo)
<Signature (name: str, baz: float, bar: int = 12) -> None>
>>>

Foo is just a normal class with a normal __init__.

This is no different than if you don't use dataclasses:

>>> class Bar:
...     def __init__(self, name: str, baz: float, bar: int = 12) -> None:
...         pass
...
>>> Bar()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() missing 2 required positional arguments: 'name' and 'baz'
>>> inspect.signature(Bar)
<Signature (name: str, baz: float, bar: int = 12) -> None>
>>> BarMock = unittest.mock.Mock(Bar)
>>> barMock = BarMock()
History
Date User Action Args
2019-04-09 21:56:44eric.smithsetrecipients: + eric.smith, John Parejko2
2019-04-09 21:56:44eric.smithsetmessageid: <1554847004.7.0.258028026707.issue36580@roundup.psfhosted.org>
2019-04-09 21:56:44eric.smithlinkissue36580 messages
2019-04-09 21:56:44eric.smithcreate