[Python-ideas] Proposal: Use mypy syntax for function annotations

Dennis Brakhane brakhane at googlemail.com
Thu Aug 14 21:43:39 CEST 2014


Am 14.08.2014 21:34, schrieb Skip Montanaro:

> Couldn't you do that today in Python with a suitably sophisticated
> function decorator? The range/type checking would happen before the
> user's actual function is called.

I suppose so, but I'd have to repeat myself and it would look ugly,
because I
have to tell the decorator which parameter I'm talking about.

Something like

  @do_range_check('age', 18, 100)
  @do_email_check('email')
  def register(age: int, email: str):

looks not nearly as nice.

Furthermore, my proposal allows multiple uses of annotations, without
restricting them
to a single use.

If you only use mypy, you can keep using annotations as type
declarations, when you use
some other framework that uses annotations for a different thing, you
can still use them,
only once you want to use both *and* you have a method that needs both
types of annotations
are you forced to use the tuple notation.








More information about the Python-ideas mailing list