Message416018
The problem with PEP-484 is that if one wants to use static type analysis, neither of these options are good:
- Use static annotations on functions, and additionally spec
out expectations in docstrings. Do note that the two types places
where "float" is mentioned here refer to different concepts.
This looks as if there were duplication, but there actually
isn't, since the claims are different. This is confusing as hell.
def foo(x: float) -> float:
"""Foos the barbaz
Args:
x: float, the foobar
Returns:
float, the foofoo"""
The floats in the docstring give me a guarantee: "If I feed in a float, I am guaranteed to receive back a float". The floats in the static type annotation merely say "yeah, can be float or int, and I'd call it ok in these cases" - that's a very different statement.
- Just go with static annotations, drop mention of types
from docstrings, and accept that we lose the ability to
stringently reason about the behavior of code.
With respect to this latter option, I think we can wait for "losing the ability to stringently reason about the behavior of code" to cause major security headaches. That's basically opening up the door to many problems at the level of "I can crash the webserver by requesting the url http://lpt1". |
|
Date |
User |
Action |
Args |
2022-03-25 21:57:44 | tfish2 | set | recipients:
+ tfish2, rhettinger, docs@python, Nathaniel Manista |
2022-03-25 21:57:44 | tfish2 | set | messageid: <1648245464.88.0.0285305816516.issue47121@roundup.psfhosted.org> |
2022-03-25 21:57:44 | tfish2 | link | issue47121 messages |
2022-03-25 21:57:44 | tfish2 | create | |
|