← 输入框|bugs.python.org|刷新

➜

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

作者 tfish2
收信人 Nathaniel Manista, docs@python, rhettinger, tfish2
日期 2022-03-25.21:57:44
SpamBayes Score -1.0
Marked as misclassified 是
Message-id <1648245464.88.0.0285305816516.issue47121@roundup.psfhosted.org>
In-reply-to
内容
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".
历史
日期 用户 动作 参数
2022-03-25 21:57:44tfish2修改recipients: + tfish2, rhettinger, docs@python, Nathaniel Manista
2022-03-25 21:57:44tfish2修改messageid: <1648245464.88.0.0285305816516.issue47121@roundup.psfhosted.org>
2022-03-25 21:57:44tfish2链接issue47121 messages
2022-03-25 21:57:44tfish2创建