Skip to content

bpo-32278: Add dataclasses.Data as an alias for typing.Any#4982

Closed
gpshead wants to merge 1 commit into
python:masterfrom
gpshead:dataclasses.Data
Closed

bpo-32278: Add dataclasses.Data as an alias for typing.Any#4982
gpshead wants to merge 1 commit into
python:masterfrom
gpshead:dataclasses.Data

Conversation

@gpshead

@gpshead gpshead commented Dec 22, 2017

Copy link
Copy Markdown
Member

As suggested in a recent python-dev discussion:
https://groups.google.com/d/msg/dev-python/DIFX5Gf85Gs/eg53gekFDAAJ

For people who do not want to use or promote the typing module. It
allows for the following readable idiom when one does not care to
declare types.

from dataclasses import dataclass, Data

@dataclass
class Swallow:
    weight_in_oz: Data = 5
    laden: Data = False

https://bugs.python.org/issue32278

As suggested in a recent python-dev discussion:
 https://groups.google.com/d/msg/dev-python/DIFX5Gf85Gs/eg53gekFDAAJ

For people who do not want to use or promote the typing module.  It
allows for the following readable idiom when one does not care to
declare types.

```python
from dataclasses import dataclass, Data

@DataClass
class Swallow:
    weight_in_oz: Data = 5
    laden: Data = False
```
@gpshead
gpshead requested a review from ericvsmith December 22, 2017 22:33
@gpshead gpshead changed the title Add dataclasses.Data as an alias for typing.Any bpo-32278: Add dataclasses.Data as an alias for typing.Any Dec 22, 2017
@gpshead

gpshead commented Dec 22, 2017

Copy link
Copy Markdown
Member Author

This pull request as is today obviously contains import typing... would assigning Data = 'typing.Any' work to avoid that? Even if this is a special case I expect analyzers could be made to deal with this.

@ericvsmith

Copy link
Copy Markdown
Member

In ericvsmith/dataclasses#2 (comment), Guido suggests just using object, which I think is an improvement over dataclasses.Data, or even typing.Any.

@gpshead

gpshead commented Dec 27, 2017

Copy link
Copy Markdown
Member Author

Agreed. object is a lot simpler. I was initially concerned that we shouldn't be using object for that purpose but I can't come up with any good reasons why.

@gpshead gpshead closed this Dec 27, 2017
@gpshead
gpshead deleted the dataclasses.Data branch December 28, 2017 04:24
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