On Sun, Dec 17, 2017 at 8:22 AM, Guido van Rossum <gu...@python.org> wrote:
> On Sun, Dec 17, 2017 at 2:11 AM, Julien Salort <lis...@salort.eu> wrote: > >> Naive question from a lurker: does it mean that it works also if one >> annotates with something that is not a type, e.g. a comment, >> >> @dataclass >> class C: >> a: "This represents the amplitude" = 0.0 >> b: "This is an offset" = 0.0 > > > I would personally not use the notation for this, but it is legal code. > However static type checkers like mypy won't be happy with this. > Mypy definitely won't like that use of annotation, but documentation systems might. For example, in a hover tooltip in an IDE/editor, it's probably more helpful to see the descriptive message than "int" or "float" for the attribute. What about data that isn't built-in scalars? Does this look right to people (and will mypy be happy with it)? @dataclass class C: a:numpy.ndarray = numpy.random.random((3,3)) b:MyCustomClass = MyCustomClass("foo", 37.2, 1+2j) I don't think those look terrible, but I think this looks better: @dataclass class C: a:Infer = np.random.random((3,3)) b:Infer = MyCustomClass("foo", 37.2, 1+2j) Where the name 'Infer' (or some other spelling) was a name defined in the `dataclasses` module. In this case, I don't want to use `typing.Any` since I really do want "the type of thing the default value has." -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com