A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2015-October/141923.html below:

[Python-Dev] PEP 0484 - the Numeric Tower

[Python-Dev] PEP 0484 - the Numeric Tower [Python-Dev] PEP 0484 - the Numeric TowerGuido van Rossum guido at python.org
Wed Oct 14 11:38:43 EDT 2015
Perhaps you could solve this with type variables. Here's a little
demonstration program:
```
from decimal import Decimal
from typing import TypeVar
F = TypeVar('F', float, Decimal)
def add(a: F, b: F) -> F:
    return a+b
print(add(4.2, 3.14))
print(add(Decimal('4.2'), Decimal('3.14')))
print(add(Decimal('4.2'), 3.14))
```
Note that the last line is invalid. mypy correctly finds this:
```
flt.py:8: error: Type argument 1 of "add" has incompatible value "object"
```
(We could work on the error message.)

Now, I'm not sure that this is the best solution given the audience -- but
the type variable 'F' only needs to be defined once, so this might actually
work.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20151014/6f47b348/attachment.html>
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4