Skip to content

Commit

Permalink
Handle missing attribute in mixin properly in type-check
Browse files Browse the repository at this point in the history
  • Loading branch information
alegonz committed Jan 8, 2020
1 parent 3dca2de commit 9de8e83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion baikal/_core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def fit(
fit_params = fit_params_steps.get(node.step, {})

# TODO: Add a try/except to catch missing output data errors (e.g. when forgot ensemble outputs)
node.step.fit(*Xs, *ys, **fit_params) # type: ignore # (it's a mixin)
node.step.fit(*Xs, *ys, **fit_params)

# 2) predict/transform phase
if list(self.graph.successors(node)):
Expand Down
8 changes: 6 additions & 2 deletions baikal/_core/step.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
import warnings
from typing import Any, Callable, Dict, List, Optional, Union
from typing import Any, Callable, Dict, List, Optional, Union, TYPE_CHECKING

from baikal._core.data_placeholder import DataPlaceholder, is_data_placeholder_list
from baikal._core.utils import listify, make_name, make_repr, make_args_from_attrs
Expand Down Expand Up @@ -363,6 +363,11 @@ class Step(_StepBase):
>>> logreg = LogisticRegression(C=2.0)
"""

if TYPE_CHECKING:

def fit(self, X, y, **fit_params):
return self

def __init__(self, *args, name: str = None, n_outputs: int = 1, **kwargs):
# Necessary to use this class as a mixin
super().__init__(*args, name=name, n_outputs=n_outputs, **kwargs) # type: ignore
Expand Down Expand Up @@ -598,5 +603,4 @@ def __init__(
# Notes on typing:
# mypy produces false positives with mixins, so we use type: ignore
# See:
# https://github.com/python/mypy/issues/1996
# https://github.com/python/mypy/issues/5887

0 comments on commit 9de8e83

Please sign in to comment.