@overload def init( self, pipeline: Pipeline, model: Any, verbose: int = 1, ) -> None:…
- User
@overload def init( self, pipeline: Pipeline, model: Any, verbose: int = 1, ) -> None: self._preprocessor: PreprocessorABC = pipeline._preprocessor self._featurizer: FeaturizerABC = pipeline._featurizer self._model : Any = model self._verbosity: int = verbose
codedef __init__( self, pipeline: Pipeline, verbose: int = 1, ) -> None: self._preprocessor: PreprocessorABC = pipeline._preprocessor self._featurizer: FeaturizerABC = pipeline._featurizer self._model : ClassificationModelABC | RegressionModelABC = pipeline._model self._verbosity: int = verboseIt seems like i can't call this constructor without specifying a model despite the fact that i think i overloaded it, what do you think the problem is
Assistant
The problem you're experiencing might be due to the way Python handles method overloading. Python doesn't natively support method overloading in the way that languages like Java or C++ do.
In your case, you've defined two
__init__methods with different signatures, but Python will only use the last one defined. This is because when a class is defined, the last method definition for a given name will override any previous definitions.If you want to provide optional arguments, you can do so by setting default values for those arguments. Here's how you can modify your
__init__method to accept an optionalmodelargument:pythondef __init__( self, pipeline: Pipeline, model: Any = None, verbose: int = 1, ) -> None: self._preprocessor: PreprocessorABC = pipeline._preprocessor self._featurizer: FeaturizerABC = pipeline._featurizer if model is None: self._model: ClassificationModelABC | RegressionModelABC = pipeline._model else: self._model: Any = model self._verbosity: int = verbose