seq-lang / seq

A high-performance, Pythonic language for bioinformatics
https://seq-lang.org
Apache License 2.0
700 stars 50 forks source link

Error with multimethods #112

Closed mationai closed 3 years ago

mationai commented 4 years ago
def test(a:int, b:list[int]):
    print "b of list[int] called"

def test(a:int, b:int):
    print "b of int called"

test(1, [2])
test(1, 2)

error: expected function input type 'int', but got 'list[int]'

markhend commented 4 years ago

Not sure that's supported. Looks like the second def shadows the first. You could do something like:

def test[T](a:int, b:T):
    print f"{a=}, {b=}"

test(1, [2])
test(1, 2)
inumanag commented 4 years ago

Yes, currently we do not support overloaded functions (only overloaded magic methods in class definitions are supported), and the latest definition will shadow the previous ones. We will handle this better once the union types land in develop.

inumanag commented 3 years ago

Resolved in #132.

Overloaded functions are not supported (class method, though, are). You can use instead isinstance that is a compile-time check and that will have the desired effect:

def test(a, b):
   if ininstance(b, List[int]): ...
   elif isinstance(b, int): ...