Oh I’m well aware. Took me a solid year to appreciate type annotations for what they are and yeah I’m happy using what we have in stdlib now and not messing with mypy tyvm. The problem is that history is lost to newcomers who have very different expectations. Modern IDE’s mostly solve it though, so for all my Java peeps dipping their toes into the snake waters, listen to your ide
i mean, i’m all for rejiggering the internals. i’ve personally written at least two libraries that uses type annotations in reverse to force arguments into the correct type, and i feel like that should probably be a separate mechanism to “just call the annotation”
i think we’re talking about different things. you use enforce to mean “validate”, i used it to mean “coerce”. one of the cases was a command rine argument parser that consisted of a single decorator, so you could write
and call it with $ myfile.py foo --bar3--baz2.2 and it would print 13.4
another was about creating working protocol buffers from an excel sheet, nested types and enums and oneofs and everything. we used it to parameterize tests of our bluetooth protocol.
Oh I’m well aware. Took me a solid year to appreciate type annotations for what they are and yeah I’m happy using what we have in stdlib now and not messing with mypy tyvm. The problem is that history is lost to newcomers who have very different expectations. Modern IDE’s mostly solve it though, so for all my Java peeps dipping their toes into the snake waters, listen to your ide
i mean, i’m all for rejiggering the internals. i’ve personally written at least two libraries that uses type annotations in reverse to force arguments into the correct type, and i feel like that should probably be a separate mechanism to “just call the annotation”
dataclasses do this for you at the class level. They enforce type annotations at instantiation.
https://docs.python.org/3/library/dataclasses.html
i think we’re talking about different things. you use enforce to mean “validate”, i used it to mean “coerce”. one of the cases was a command rine argument parser that consisted of a single decorator, so you could write
@command def foo(bar: int, baz: float): print(baz * 2 + foo * 3)
and call it with
$ myfile.py foo --bar 3 --baz 2.2
and it would print 13.4another was about creating working protocol buffers from an excel sheet, nested types and enums and oneofs and everything. we used it to parameterize tests of our bluetooth protocol.