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 type hints #7

Merged
merged 7 commits into from
Jan 30, 2024
Merged

Add type hints #7

merged 7 commits into from
Jan 30, 2024

Conversation

mynhardtburger
Copy link
Member

@mynhardtburger mynhardtburger commented Jan 27, 2024

Add type hints.

Signed-off-by: Mynhardt Burger <mynhardt@gmail.com>
Copy link
Collaborator

@gabe-l-hart gabe-l-hart left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this Mynhardt! It looks like we have some backwards-compatibility issues with some of the type hints. Also, we don't have black/isort configured in CI (would be a good thing to add), but we should try to stick to that styling as much as possible while staying consistent with the current codebase (context: this tool was written before the team adopted those tools).

@@ -11,16 +11,16 @@
import os
import re
import copy
import typing
from typing import Optional, Any, Type
Copy link
Collaborator

Choose a reason for hiding this comment

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

NIT: import sorting

'''Wrapper around Python dict to make it accessible like an object.
'''
def __init__(self, input_map):
def __init__(self, input_map:dict[str, Any]):
Copy link
Collaborator

Choose a reason for hiding this comment

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

NIT here and in many other places. Let's add a (space) between the : and the hint

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, let's use Dict instead of dict for compatibility

"""Returns the class to be used to recursively build the config object"""
return AttributeAccessDict

# BELOW MAKES INSTANCE ACCESSIBLE VIA NATIVE PYTHON DICT METHODS ###############################

def __getattr__(self, key, default=None):
def __getattr__(self, key:str, default:Any=None):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def __getattr__(self, key:str, default:Any=None):
def __getattr__(self, key: str, default: Any = None) -> Any:

@@ -49,7 +49,7 @@ def __init__(self, input_map):
super().__init__(**copied_map)

@classmethod
def _make_attribute_access_dict(cls, value):
def _make_attribute_access_dict(cls, value:Any):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Return type annotation

@@ -169,7 +169,7 @@ def __init__(self, config, override_env_vars=True):
super().__init__(updated_config)

@classmethod
def from_yaml(cls, config_location=None, **kwargs):
def from_yaml(cls, config_location:str, **kwargs:Any):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Return type

@@ -192,7 +192,7 @@ def from_yaml(cls, config_location=None, **kwargs):
return cls(loaded_config, **kwargs)

@staticmethod
def _verify_config_location(config_location):
def _verify_config_location(config_location: str):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def _verify_config_location(config_location: str):
def _verify_config_location(config_location: str) -> bool:

Copy link
Member Author

Choose a reason for hiding this comment

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

Note that _verify_config_location doesn't return a bool, but a str.

Signed-off-by: Mynhardt Burger <mynhardt@gmail.com>
Signed-off-by: Mynhardt Burger <mynhardt@gmail.com>
Signed-off-by: Mynhardt Burger <mynhardt@gmail.com>
Signed-off-by: Mynhardt Burger <mynhardt@gmail.com>
Copy link
Collaborator

@gabe-l-hart gabe-l-hart left a comment

Choose a reason for hiding this comment

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

Very nice! Thanks for fixing all the quotes too

Signed-off-by: Mynhardt Burger <mynhardt@gmail.com>
Copy link
Collaborator

@gabe-l-hart gabe-l-hart left a comment

Choose a reason for hiding this comment

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

One more!

aconfig/aconfig.py Outdated Show resolved Hide resolved
Signed-off-by: Mynhardt Burger <mynhardt@gmail.com>
Copy link
Collaborator

@gabe-l-hart gabe-l-hart left a comment

Choose a reason for hiding this comment

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

Ship it!

@gabe-l-hart gabe-l-hart merged commit e4c74fc into IBM:main Jan 30, 2024
2 checks passed
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