Thomas Fischbacher <tf...@google.com> added the comment:

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";.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue47121>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to