-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
Signed-off-by: Mynhardt Burger <mynhardt@gmail.com>
There was a problem hiding this 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).
aconfig/aconfig.py
Outdated
@@ -11,16 +11,16 @@ | |||
import os | |||
import re | |||
import copy | |||
import typing | |||
from typing import Optional, Any, Type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: import sorting
aconfig/aconfig.py
Outdated
'''Wrapper around Python dict to make it accessible like an object. | ||
''' | ||
def __init__(self, input_map): | ||
def __init__(self, input_map:dict[str, Any]): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
aconfig/aconfig.py
Outdated
"""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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def __getattr__(self, key:str, default:Any=None): | |
def __getattr__(self, key: str, default: Any = None) -> Any: |
aconfig/aconfig.py
Outdated
@@ -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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return type annotation
aconfig/aconfig.py
Outdated
@@ -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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return type
aconfig/aconfig.py
Outdated
@@ -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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def _verify_config_location(config_location: str): | |
def _verify_config_location(config_location: str) -> bool: |
There was a problem hiding this comment.
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>
There was a problem hiding this 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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more!
Signed-off-by: Mynhardt Burger <mynhardt@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ship it!
Add type hints.