Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions Lib/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,12 @@ def __repr__(self):
return '<factory>'
_HAS_DEFAULT_FACTORY = _HAS_DEFAULT_FACTORY_CLASS()

# A sentinel object to detect if a parameter is supplied or not. Use
# a class to give it a better repr.
class _MISSING_TYPE:
pass
MISSING = _MISSING_TYPE()
# A sentinel object to detect if a parameter is supplied or not.
MISSING = sentinel("MISSING")

# A sentinel object to indicate that following fields are keyword-only by
# default. Use a class to give it a better repr.
class _KW_ONLY_TYPE:
pass
KW_ONLY = _KW_ONLY_TYPE()
# default.
KW_ONLY = sentinel("KW_ONLY")

# Since most per-field metadata will be unused, create an empty
# read-only dictionary that can be shared among all fields.
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_dataclasses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ class D:
self.assertNotIn('x', D.__dict__)

def test_missing_repr(self):
self.assertIn('MISSING_TYPE object', repr(MISSING))
self.assertEqual(repr(MISSING), 'MISSING')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea why the arguments were in the opposite order before, but changing them is a definite improvement!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And yes, I realize that wasn't really the point of this change.


def test_dont_include_other_annotations(self):
@dataclass
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:data:`dataclasses.MISSING` and :data:`dataclasses.KW_ONLY` are now
instances of :class:`sentinel`.
Loading