Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc questions, suggestions, and error corrections for dataclasses #4726

Closed
wants to merge 3 commits into from

Conversation

rhettinger
Copy link
Contributor

@rhettinger rhettinger commented Dec 5, 2017

These are for Eric's consideration:

  • Fix typo leading to a SyntaxError in the make_dataclass docstring
  • Let make_dataclass pass through keyword arguments (ordered, hash, frozen, etc)
  • Replace "len(s)==0" with the faster and more idiomatic (PEP 8ish) "not s"
  • Ask whether asdict() should return an OrderedDict instead of a regular dict
  • Even though the class implementation details have "hash=None" as a way of turning off hashing, the dataclass API should use regular booleans and have the default be "hash=False" (as equivalent to "hash=None"). It is a bit of an API landmine to have hashing succeed in this example:
>>> from dataclasses import dataclass
>>> @dataclass(hash=False)
... class C:
...     x: int
...
>>> hash(C(999))
-9223372036585142703

@ericvsmith
Copy link
Member

Thanks, @rhettinger. @serhiy-storchaka had many of these suggestions over at #4704, and I've been working on a patch for his issues. I'll answer your questions when I have a few minutes to devote to it, but it will probably have to wait until the weekend.

@ericvsmith
Copy link
Member

Of the original issues, I think most have been addressed in subsequent commits (many not by me).

The remaining issues are:

  • use "if fields" instead of "if len(fields) == 0"
  • an issue with hashing.

I'm still investigating all of the hashing implications, and how it interacts with bpo-32513.

For the "if fields" issue, I'll just go ahead and commit that when I'm making other changes to dataclasses. So, I think this PR can be closed. I'll close it once I'm done with the hashing questions.

@rhettinger rhettinger closed this Dec 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants