Skip to content

Commit

Permalink
fix: type annotations were erroneous
Browse files Browse the repository at this point in the history
  • Loading branch information
MultifokalHirn committed Dec 21, 2023
1 parent 6e419a4 commit cae7a56
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repos:
# rev: v1.7.1
# hooks:
# - id: mypy
# additional_dependencies: [types-all, pydantic]
# additional_dependencies: [types-all]
# args: [--config-file=./pyproject.toml]
# files: ^src/
# entry: mypy src/
Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ ci = {shell = """ \


[tool.mypy]
plugins = ["pydantic.mypy"]
# plugins = ["pydantic.mypy"]
disallow_any_unimported = false
ignore_missing_imports = true
pretty = true
Expand All @@ -143,10 +143,10 @@ warn_unused_ignores = false
files = ["src/**/*.py"]
exclude = ["tests/**/*.py", "docs/**/*.py"]

[tool.pydantic-mypy]
init_forbid_extra = true
init_typed = true
warn_required_dynamic_aliases = true
# [tool.pydantic-mypy]
# init_forbid_extra = true
# init_typed = true
# warn_required_dynamic_aliases = true

[tool.coverage.run]
source = ["src/ornaments"]
Expand Down
8 changes: 4 additions & 4 deletions src/ornaments/invariants/only_called_once.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ..scopes import CLASS_SCOPE, OBJECT_SCOPE, SESSION_SCOPE


def only_called_once(scope="object", enforce: bool = False) -> Callable[..., Callable[..., Any]]:
def only_called_once(scope: str = "object", enforce: bool = False) -> Callable[..., Any]:
"""
Decorator that ensures a function is only called once in a given scope.
Expand All @@ -21,9 +21,9 @@ def my_function() -> str:
```
"""

def decorator(func: Callable) -> Callable:
def decorator(func: Callable[..., Any]) -> Callable[..., Any]:
@wraps(wrapped=func)
def wrapper(*args, **kwargs) -> Any:
def wrapper(*args: Any, **kwargs: Any) -> Any:
if scope in OBJECT_SCOPE:
# Use the id of the instance for object scope
call_scope = (id(args[0]), func)
Expand All @@ -34,7 +34,7 @@ def wrapper(*args, **kwargs) -> Any:
call_scope = (args[0].__class__, func)
elif scope in SESSION_SCOPE: # session scope
# Use the function itself as identifier for session scope
call_scope = (func,)
call_scope = (id(func), func)
else:
raise ValueError(f"Invalid scope. Must be one of {OBJECT_SCOPE | CLASS_SCOPE | SESSION_SCOPE}.")

Expand Down
8 changes: 4 additions & 4 deletions src/ornaments/scopes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Final

CLASS_SCOPE: Final[set] = {"class"}
SESSION_SCOPE: Final[set] = {"session"}
OBJECT_SCOPE: Final[set] = {"instance", "object"}
ALL_SCOPES: Final[set] = CLASS_SCOPE | SESSION_SCOPE | OBJECT_SCOPE
CLASS_SCOPE: Final[set[str]] = {"class"}
SESSION_SCOPE: Final[set[str]] = {"session"}
OBJECT_SCOPE: Final[set[str]] = {"instance", "object"}
ALL_SCOPES: Final[set[str]] = CLASS_SCOPE | SESSION_SCOPE | OBJECT_SCOPE

0 comments on commit cae7a56

Please sign in to comment.