Skip to content

Engwer/python-overloaded-functions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Overloaded functions in python

This is an example of how overloaded functions can be implemented in python. The underlying idea is that functions are only called with keyword arguments and their type is matched according to the type hints in the function declaration. If no matching function can be found, an AttributeError is raised.

Example:

    >>> func(a=1, b=2)
    3
    >>> func(a=1, b=[2, 3])
    6
    >>> func(a=[3, 2], b=[2, 3, 4])
    12
    >>> func(a=[3, 2], b=(2, 3, 4))
    Traceback (most recent call last):
    AttributeError: Function parameters do not match any overloaded function

Missing features

  • Positional features
  • Nested type hints such as typing.List[int]
  • Different number of arguments

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages