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

test: add type hints to test_framework #1025

Merged
merged 14 commits into from
Oct 3, 2023
Merged
8 changes: 6 additions & 2 deletions ops/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,13 +1061,17 @@ def __init__(self, parent: Object, attr_name: str):

if TYPE_CHECKING:
@typing.overload
def __getattr__(self, key: Literal['on']) -> ObjectEvents: # type: ignore
def __getattr__(self, key: Literal['on']) -> ObjectEvents:
pass

@typing.overload
def __getattr__(self, key: str) -> Any:
tonyandrewmeyer marked this conversation as resolved.
Show resolved Hide resolved
pass

def __getattr__(self, key: str) -> Any:
# "on" is the only reserved key that can't be used in the data map.
if key == "on":
return self._data.on # type: ignore # casting won't work for some reason
return self._data.on
if key not in self._data:
raise AttributeError(f"attribute '{key}' is not stored")
return _wrap_stored(self._data, self._data[key])
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ include = ["ops/*.py", "ops/_private/*.py",
"test/test_testing.py",
"test/test_storage.py",
"test/test_charm.py",
"test/test_framework.py",
]
pythonVersion = "3.8" # check no python > 3.8 features are used
pythonPlatform = "All"
Expand Down
Loading
Loading