Message339228
+1 for a command-line option decouples this from eliminating docstrings. The latter generally has no semantic effect, but the former might.
Ideally, we don't want to break non-typing uses of annotations. One example below uses annotations for argument validation and documentation. Another example would be the using __annotations__ for dynamic dispatch.
--- Example -----------------------------------------------------------
>>> class Limit:
def __init__(self, low, high):
self.low = low
self.high = high
def valid(self, x):
return self.low <= x <= self.high
def __repr__(self):
return f'{type(self).__name__}(low={self.low}, high={self.high})'
>>> def validate(function, parameter, value):
assert function.__annotations__[parameter].valid(value)
>>> def maneuver(thrust: Limit(100, 150), angle: Limit(-10, 20)):
'Engage OMS burn (orbital maneuvering system).'
validate(maneuver, 'thrust', thrust)
validate(maneuver, 'angle', angle)
...
>>> help(maneuver)
Help on function maneuver in module __main__:
maneuver(thrust: Limit(low=100, high=150), angle: Limit(low=-10, high=20))
Engage OMS burn (orbital maneuvering system).
>>> maneuver(120, 7)
>>> maneuver(120, 35)
Traceback (most recent call last):
File "<pyshell#41>", line 1, in <module>
maneuver(120, 35)
File "<pyshell#38>", line 4, in maneuver
validate(maneuver, 'angle', angle)
File "<pyshell#30>", line 2, in validate
assert function.__annotations__[parameter].valid(value)
AssertionError |
|
Date |
User |
Action |
Args |
2019-03-30 23:04:08 | rhettinger | set | recipients:
+ rhettinger, gvanrossum, levkivskyi, cary |
2019-03-30 23:04:08 | rhettinger | set | messageid: <1553987048.48.0.379843400096.issue36466@roundup.psfhosted.org> |
2019-03-30 23:04:08 | rhettinger | link | issue36466 messages |
2019-03-30 23:04:08 | rhettinger | create | |
|