Commit Graph

16 Commits

Author SHA1 Message Date
Stephen Rosen
38d32a916c Use enum trick for dataclasses.MISSING (#7127)
The goal of this change is to fix the behavior of
`dataclasses.Field`. Several attributes of a `Field` may have a value
of `MISSING` (a sentinel value). As a result, attributes of Field may
be checked against `MISSING` as in

     [f for f in fields(obj) if f.default is MISSING]

`default`, `default_factory`, and `kw_only` are the attributes
which may have a value of `MISSING`.

This workaround of defining `_MISSING_TYPE` as an enum, and `MISSING`
as its only member, allows `... | Literal[_MISSING_TYPE.MISSING]` to
be used in type annotations for these attributes. This is very
slightly inaccurate -- primarily in that `_MISSING_TYPE` isn't really
an enum -- but this allows for use in `Literal`.
After PEP 661 (Sentinel Values), there may be a more accurate way of
writing this, but for now this works.

This adjustment is only applied to the attributes of Field, not the
arguments to functions and methods.
2022-02-04 21:21:12 -08:00
Alex Waygood
a40d79a4e6 Use lowercase type everywhere (#6853) 2022-01-08 16:09:29 +01:00
Alex Waygood
8d5d2520ac Use PEP 585 syntax wherever possible (#6717) 2021-12-28 11:31:43 +01:00
Stephen Rosen
df0a724c0f Always import Protocol from typing in stubs (#6617) 2021-12-17 13:12:22 +01:00
Sebastian Rittau
c900c0e769 Fix Python 3.10.1 problems pointed out by stubtest (#6604)
Co-authored-by: Akuli <akuviljanen17@gmail.com>
2021-12-16 07:05:45 -08:00
Akuli
994b69ef8f Use lowercase tuple where possible (#6170) 2021-10-14 17:18:19 -07:00
Bas van Beek
b9e1d7d522 Replace Mapping with types.MappingProxyType (#6013)
Mark `Signature.parameters` and `.return_annotation` as read-only properties
2021-09-09 09:58:53 +02:00
Akuli
ce11072dbe Big diff: use lower-case list and dict (#5888) 2021-08-08 09:26:35 -07:00
Kyle Altendorf
4b77d454bd dataclasses: Allow Any keys for the metadata field (#5823) 2021-08-08 15:50:52 +02:00
Akuli
ee487304d7 Big diff: Use new "|" union syntax (#5872) 2021-08-08 11:05:21 +02:00
Eric Traut
ea4be02bab Redefined dataclasses.KW_ONLY (#5826)
Redefined dataclasses.KW_ONLY so it's a type alias rather than a class instance. Class instances are illegal to use within a type annotation.
2021-08-01 08:06:48 -07:00
Shantanu
04f0113d16 dataclasses: work around default factory issues (#5718) 2021-07-01 08:07:00 +02:00
Shantanu
4bfdba71cb dataclasses: update for py310 (#5525) 2021-05-25 14:43:06 +02:00
Sebastian Rittau
45916045c8 Upgrade black to 21.4b0 and reformat (#5250)
This introduces newlines before decorators.
2021-04-26 13:58:27 +02:00
Adrian Freund
ff91f5630b Added match_args parameter to dataclass (bpo-43764) (#5212)
https://bugs.python.org/issue43764
2021-04-12 15:42:43 -07:00
Ivan Levkivskyi
16ae4c6120 Re-organize directory structure (#4971)
See discussion in #2491

Co-authored-by: Ivan Levkivskyi <ilevkivskyi@dropbox.com>
2021-01-27 12:00:39 +00:00