fork download
  1. from typing import overload
  2.  
  3. @overload
  4. def foo(x: int) -> int:
  5. ...
  6.  
  7. @overload
  8. def foo(x: float) -> float:
  9. ...
  10.  
  11. # The actual, single definition of foo that can be used:
  12. def foo(x):
  13. print(type(x))
  14. return 2 * x
  15.  
  16. print(foo(1))
  17. print(foo(1.0))
  18. print(foo('abc'))
Success #stdin #stdout 0.24s 16900KB
stdin
Standard input is empty
stdout
<class 'int'>
2
<class 'float'>
2.0
<class 'str'>
abcabc