Skip to content
/ pover Public

Python OVERloading (pover) methods with type hints

License

Notifications You must be signed in to change notification settings

idf/pover

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pover

Python OVERloading (pover) methods with type hints

It is equipped with fast overloading methods look up, minimal runtime footprint, overloading methods at class construction time.

Install

pip3 install pover

Example

All you need is pover.OverloadMeta. Simply declare your class with metaclass pover.OverloadMeta

#!/usr/bin/env python3
import unittest
import pover


class Foo(metaclass=pover.OverloadMeta):
    def add(self, a: int):
        return a + 1

    def add(self, a: list):
        return a + [1]

    def add(self, a: set):
        a.add(1)
        return a

    def minus(self, a: int):
        return a - 1

    def minus(self, a: str):
        return a[:-1]


class OverloadTest(unittest.TestCase):
    def test_overload(self):
        foo = Foo()
        self.assertEqual(foo.add(1), 2)
        self.assertEqual(foo.add([0]), [0, 1])
        self.assertEqual(foo.add({0}), {0, 1})
        self.assertEqual(foo.minus(1), 0)
        self.assertEqual(foo.minus("hello"), "hell")

Run tests:

python3 -m unittest pover.tests.tests

Supports

It requires python >=3.5.

It supports all native python types like int, set, list, dict etc. as well as your custom classes class MyClass.

It does not support typing module like typing.List, typing.Tuple, but you can use the native list, tuple instead.

Future

Support keyword arguments.

Releases

No releases published

Packages

No packages published

Languages