Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NotImplementedError: You should not call an overloaded function

@overload
def setSize(self,size:tuple[int|str])->None:
    '''
    Set image size (width,height)
    '''
    try:self.options.append(f"width=\"{str(size[0])}\" height=\"{str(size[1])}\"")
    except IndexError:print("Error reading the size, aborting")
@overload
def setSize(self,width:int|str,height:int|str)->None:
    '''
    Set image Size
    '''
    self.setSize((width,height))

This is my code and I called this function as var.setSize((500,500)) which would normally call the top one but I got this error:

NotImplementedError: You should not call an overloaded function. A series of @overload-decorated functions outside a stub module should always be followed by an implementation that is not @overload-ed.
like image 357
user19926715 Avatar asked Feb 04 '26 00:02

user19926715


1 Answers

When writing code with function overloading in Python, it is important to remember that

[y]ou should not call an overloaded function. A series of @overload-decorated functions outside a stub module should always be followed by an implementation that is not @overload-ed.

This is because @overload-ed functions are intended to simply declare the types of the arguments without providing an actual implementation. Therefore, an implementation must be provided following the @overload-ed functions in order for the code to be valid.

like image 172
Otabek Butcher Avatar answered Feb 06 '26 14:02

Otabek Butcher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!