[docs] [issue36661] Missing dataclass decorator import in dataclasses module docs

Mark turner report at bugs.python.org
Sun Jun 23 20:07:25 EDT 2019


Mark turner <mturner865 at gmail.com> added the comment:

I tried a couple of the examples from the docs and found the setup to be a little confusing
amd inconsistent. For example, the decorator line "@decorator" requires you to use

from dataclasses import dataclass

while the example line "mylist: List[int] = field(default_factory=list)" requires you to use these

import dataclasses
import typing

and must be modified to
mylist: typing.List[int] = dataclasses.field(default_factory=list)

The decorator line could be modified to be
@dataclasses.dataclass
and the from/import line could be eliminated. But that seems awkward.

So, what is are best practices for handling the imports needed by these examples?
And should the examples be updated to be consistent with a best practice set of imports?
Or am I not understanding how this code works?

Also, the intro section states "If any of the added methods already exist on the class, a TypeError will be raised."
This statement seems incorrect and contrdicts the parameter documentation that follows.

----------
nosy: +mturner865

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36661>
_______________________________________


More information about the docs mailing list