~shakna/dyndispatch

This is an experimental library, for enabling dynamic dispatch in Python.
That was way easier than expected...

You can also use your local clone with git send-email.

#dyndispatch

This is an experimental library, for enabling dynamic dispatch in Python.

It has no dependencies other than the standard library.

import dyndispatch

@dyndispatch.overload
def thing(a, b, c):
    return "V1"

@dyndispatch.overload
def thing(a, b, c, d):
    return "V2"

assert thing(1, 2, 3, 4) == "V2"

assert thing(1, 2, 3) == "V1"

try:
	thing(1, 2)
	assert False
except TypeError:
	assert True

#Does it work with generators?

Probably. There's some funky stuff around closures that may or may not work. Hard to tell right now.

#Does it work with class methods?

Probably not.

There is a possibility for getting it to work in future, but it will probably double the size of the current code. I'll need to give it some thought.

#Is it thread-safe?

Not even a little. It uses globals to do some dumb stuff, so we don't need to instance an object.

#Why did you make this...?

The power has been out for three hours, and it is 34C here. I was bored, and had an idea.

Simple, easy, and not requiring online documentation was sort of a must for occupying my brain in the heat.


#License

Making use of this project is not a good idea at this stage.

However, see the LICENSE.md file.