[Python-Dev] Is static typing still optional? (original) (raw)
Paul Moore p.f.moore at gmail.com
Fri Dec 22 15:11:38 EST 2017
- Previous message (by thread): [Python-Dev] Is static typing still optional?
- Next message (by thread): [Python-Dev] Is static typing still optional?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 22 December 2017 at 19:50, Gregory P. Smith <greg at krypto.org> wrote:
My preference for this is "just use Any" for anyone not concerned about the type. But if we wanted to make it more opaque so that people need not realizing that they are actually type annotations, I suggest adding an alias for Any in the dataclasses module (dataclasses.Data = typing.Any)
from dataclasses import dataclass, Data @dataclass class Swallow: weightinoz: Data = 5 laden: Data = False species: Data = SwallowSpecies.AFRICAN the word "Data" is friendlier than "Any" in this context for people who don't need to care about the typing module. We could go further and have Data not be an alias for Any if desired (so that its repr wouldn't be confusing, not that anyone should be looking at its repr ever).
That sounds like a nice simple proposal. +1 from me.
Documentation can say that variables should be annotated with "Data" to be recognised by the decorator, and if people are using type annotations an actual type can be used in place of "Data" (which acts the same as typing.Any. That seems to me to describe the feature in a suitably type-hinting-neutral way, while still making it clear how data classes interact with type annotations.
Paul
- Previous message (by thread): [Python-Dev] Is static typing still optional?
- Next message (by thread): [Python-Dev] Is static typing still optional?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]