[Python-Dev] Is static typing still optional? (original) (raw)

David Mertz mertz at gnosis.cx
Fri Dec 22 15:29:48 EST 2017


There name Data seems very intuitive to me without suggesting type declaration as Any does (but it can still be treated as a synonym by actual type checkers)

On Dec 22, 2017 12:12 PM, "Paul Moore" <p.f.moore at gmail.com> wrote:

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


Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/ mertz%40gnosis.cx -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20171222/c50c6e1b/attachment-0001.html>



More information about the Python-Dev mailing list