[Python-ideas] PEP 484 (Type Hints) -- first draft round

Ethan Furman ethan at stoneleaf.us
Fri Jan 23 10:09:46 CET 2015

On 01/22/2015 09:23 PM, Guido van Rossum wrote:
> On Thu, Jan 22, 2015 at 8:45 PM, Terry Reedy wrote:
>> 3. Users may want to add or customize annotations (perhaps to narrow the
>> allowed arguments to conform to policy).  This is better done in a separate
>> file.
> I don't understand this part. Can you clarify, maybe give an example?

As a guess, if somebody has a library function that is somewhat generic, but they will only be using it with a specific
type, then having a stub file with that more specific information would help catch bugs where a type is being passed in
that is not the required specific type, even though it satisfies the more generic type in the library's annotations.
Something like:

--8< actual_lib.py -------------------------------
def cool_adder_func(a:Number, b:Number): -> Number
  return a + b
--8< ---------------------------------------------

--8< overriding stub file -----------------------
def cool_adder_func(a:int, b:int): -> int
--8< --------------------------------------------

--8< application --------------------------------
  cool_adder_func(float_var, Decimal_var)
--8< --------------------------------------------

The above would be flagged because in this application, using this stub file, cool_adder_func should only take ints.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150123/4f109dd6/attachment.sig>

More information about the Python-ideas mailing list