Skip to content

added classvar annotations #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions rectools/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ class ModelBase(tp.Generic[ModelConfig_T]):
Use derived classes instead.
"""

recommends_for_warm: bool = False
recommends_for_cold: bool = False
recommends_for_warm: tp.ClassVar[bool] = False
recommends_for_cold: tp.ClassVar[bool] = False

config_class: tp.Type[ModelConfig_T]
config_class: tp.Type[ModelConfig_T] # ClassVar cannot contain type variables

def __init__(self, *args: tp.Any, verbose: int = 0, **kwargs: tp.Any) -> None:
self.is_fitted = False
Expand Down
2 changes: 1 addition & 1 deletion rectools/models/implicit_als.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def __init__(self, model: AnyAlternatingLeastSquares, verbose: int = 0, fit_feat
self.fit_features_together = fit_features_together
self.use_gpu = isinstance(model, GPUAlternatingLeastSquares)
if not self.use_gpu:
self.n_threads = model.num_threads
self.n_threads = model.num_threads # type: ignore # TODO: remove when recommend n_threads implemented

@classmethod
def _make_config(
Expand Down
2 changes: 1 addition & 1 deletion rectools/models/lightfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def __init__(
self.model: LightFM
self._model = model
self.n_epochs = epochs
self.n_threads = num_threads
self.n_threads = num_threads # type: ignore # TODO: remove when recommend n_threads implemented
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's tricky actually. We are using it in LightFM for fit also. Let's please remove this comment here and discuss it in our recommend n_threads PR.
Also it is more menaingfull to move this comment to vector.py


def _get_config(self) -> LightFMWrapperModelConfig:
inner_model = self._model
Expand Down
6 changes: 3 additions & 3 deletions rectools/models/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class Factors:
class VectorModel(ModelBase[ModelConfig_T]):
"""Base class for models that represents users and items as vectors"""

u2i_dist: Distance = NotImplemented
i2i_dist: Distance = NotImplemented
n_threads: int = 0 # TODO: decide how to pass it correctly for all models
u2i_dist: tp.ClassVar[Distance] = NotImplemented
i2i_dist: tp.ClassVar[Distance] = NotImplemented
n_threads: tp.ClassVar[int] = 0 # TODO: decide how to pass it correctly for all models

def _recommend_u2i(
self,
Expand Down
Loading