Skip to content
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

Add typehints to much of the core code. #379

Merged
merged 14 commits into from
Sep 13, 2023
Merged

Add typehints to much of the core code. #379

merged 14 commits into from
Sep 13, 2023

Conversation

stephenpardy
Copy link
Contributor

Partially addresses #368

Adds partial type hints throughout the code.
Leaves almost all logic untouched. One exception are areas where the default argument was a list. This has been changed to None with the list added in the function body. This is to avoid the mutable default argument issue.


What

  • Adds type hints throughout the code

How to Test

  • Relying on existing unit tests.
  • Can run mypy - will still show around 100 issues.

@stephenpardy stephenpardy marked this pull request as ready for review September 12, 2023 19:00
@stephenpardy stephenpardy requested a review from a team as a code owner September 12, 2023 19:00
Copy link
Member

@ryanSoley ryanSoley left a comment

Choose a reason for hiding this comment

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

this is awesome! thanks for getting us started down this path!

I have a few general questions and also noted a few functions were you missed a variable or two - lmk if any of those omissions were intentional

@@ -9,19 +19,22 @@ class Base:
The config, which injects the repository to use.
"""

def __init__(self, domain, config=None):
def __init__(self, domain: DOMAIN_TYPES, config: Optional[Config] = None):
Copy link
Member

Choose a reason for hiding this comment

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

I have to look into why the config is optional - that doesn't seem right

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the default value here is None, do we need to make it required?

Copy link
Member

Choose a reason for hiding this comment

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

not in this PR, maybe in the future. I think its a remnant of the fact that Rubicon used to extend the Base and didn't take in a config since it generated it. I'll verify that's the case and if so make an issue to fix it

@@ -29,18 +35,22 @@ class Config:
"""

PERSISTENCE_TYPES = ["filesystem", "memory"]
REPOSITORIES = {
REPOSITORIES: Dict[str, Type[BaseRepository]] = {
Copy link
Member

Choose a reason for hiding this comment

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

why do we need the Type here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Type here means that the dictionary contains uninstantiated classes.

Copy link
Member

Choose a reason for hiding this comment

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

ahh gotcha, makes sense

@@ -47,14 +60,14 @@ def _validate_data(self, data_bytes, data_file, data_object, data_path, name):
@failsafe
def log_artifact(
self,
data_bytes=None,
data_bytes: Optional[bytes] = None,
data_file=None,
Copy link
Member

Choose a reason for hiding this comment

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

missed one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks.

@failsafe
def log_dataframe(self, df, description=None, name=None, tags=[]):
def log_dataframe(
self, df: Union[pd.DataFrame, dd.DataFrame], description=None, name=None, tags=[]
Copy link
Member

Choose a reason for hiding this comment

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

missed the last couple

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks.

"""Get the parameter's name."""
return self._domain.name

@property
def value(self):
def value(self) -> Optional[Union[object, float]]:
Copy link
Member

Choose a reason for hiding this comment

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

isn't Union[object, float] == object?

"""Get the parameter's value."""
return self._domain.value
return getattr(self._domain, "value", None)
Copy link
Member

Choose a reason for hiding this comment

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

why is this necessary? a parameter domain should never not have a value key

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. This was because I didn't hint the _domain value properly.

Comment on lines 38 to 39
root_dir=None,
auto_git_enabled=False,
Copy link
Member

Choose a reason for hiding this comment

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

missed a couple

Copy link
Member

@ryanSoley ryanSoley left a comment

Choose a reason for hiding this comment

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

looks great!

@stephenpardy stephenpardy merged commit 4862509 into main Sep 13, 2023
5 of 6 checks passed
@stephenpardy stephenpardy deleted the spardy/typehints branch September 13, 2023 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants