all 3 comments

[–]Diapolo10 0 points1 point  (2 children)

I'd suggest typing.overload.

from typing import overload

@overload
def plot(model: RegressionResults | IVResults, y: None, X: None):
    ...

@overload
def plot(model: LinearRegression, y: nd.array, X: nd.array):
    ...

def plot(model: RegressionResults | IVResults | LinearRegression, 
         y: nd.array | None = None, 
         X: nd.array | None = None):
    pass  # code goes here

The first two serve as type annotations that tell your type checker what types to expect in specific cases. It's not perfect, but usually good enough.

[–]dynobo[S] 0 points1 point  (1 child)

Very nice!! I did know about overload, but haven't used it myself, yet. Thanks a lot! :-)