Skip to content

Fix overloaded function error #66

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

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions apricot/cache/local_cache.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations

from typing import Self, overload
from typing import Self

from typing_extensions import override

from .uid_cache import UidCache

Expand All @@ -12,18 +14,18 @@ def __init__(self: Self) -> None:
"""Initialise a RedisCache."""
self.cache: dict[str, int] = {}

@overload # type: ignore[misc]
@override
def get(self: Self, identifier: str) -> int | None:
return self.cache.get(identifier, None)

@overload # type: ignore[misc]
@override
def keys(self: Self) -> list[str]:
return [str(k) for k in self.cache]

@overload # type: ignore[misc]
@override
def set(self: Self, identifier: str, uid_value: int) -> None:
self.cache[identifier] = uid_value

@overload # type: ignore[misc]
@override
def values(self: Self, keys: list[str]) -> list[int]:
return [v for k, v in self.cache.items() if k in keys]
11 changes: 6 additions & 5 deletions apricot/cache/redis_cache.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

from typing import Self, cast, overload
from typing import Self, cast

import redis
from typing_extensions import override

from .uid_cache import UidCache

Expand Down Expand Up @@ -36,19 +37,19 @@ def cache(self: Self) -> redis.Redis[str]:
)
return self.cache_

@overload # type: ignore[misc]
@override
def get(self: Self, identifier: str) -> int | None:
value = self.cache.get(identifier)
return None if value is None else int(value)

@overload # type: ignore[misc]
@override
def keys(self: Self) -> list[str]:
return [str(k) for k in self.cache.keys()] # noqa: SIM118

@overload # type: ignore[misc]
@override
def set(self: Self, identifier: str, uid_value: int) -> None:
self.cache.set(identifier, uid_value)

@overload # type: ignore[misc]
@override
def values(self: Self, keys: list[str]) -> list[int]:
return [int(cast("str", v)) for v in self.cache.mget(keys)]
10 changes: 6 additions & 4 deletions apricot/oauth/keycloak_client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import annotations

import operator
from typing import TYPE_CHECKING, Any, Self, cast, overload
from typing import TYPE_CHECKING, Any, Self, cast

from typing_extensions import override

from .oauth_client import OAuthClient

Expand Down Expand Up @@ -45,12 +47,12 @@ def __init__(
**kwargs,
)

@overload # type: ignore[misc]
@override
@staticmethod
def extract_token(json_response: JSONDict) -> str:
return str(json_response["access_token"])

@overload # type: ignore[misc]
@override
def groups(self: Self) -> list[JSONDict]:
output = []
try:
Expand Down Expand Up @@ -110,7 +112,7 @@ def groups(self: Self) -> list[JSONDict]:
self.logger.warn(msg)
return output

@overload # type: ignore[misc]
@override
def users(self: Self) -> list[JSONDict]:
output = []
try:
Expand Down
10 changes: 6 additions & 4 deletions apricot/oauth/microsoft_entra_client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import annotations

import operator
from typing import TYPE_CHECKING, Any, Self, cast, overload
from typing import TYPE_CHECKING, Any, Self, cast

from typing_extensions import override

from .oauth_client import OAuthClient

Expand Down Expand Up @@ -36,12 +38,12 @@ def __init__(
**kwargs,
)

@overload # type: ignore[misc]
@override
@staticmethod
def extract_token(json_response: JSONDict) -> str:
return str(json_response["access_token"])

@overload # type: ignore[misc]
@override
def groups(self: Self) -> list[JSONDict]:
output = []
queries = [
Expand Down Expand Up @@ -81,7 +83,7 @@ def groups(self: Self) -> list[JSONDict]:
)
return output

@overload # type: ignore[misc]
@override
def users(self: Self) -> list[JSONDict]:
output = []
try:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ dependencies = [
"types-oauthlib~=3.2",
"types-redis~=4.6",
"types-requests~=2.31",
"typing-extensions~=4.12",
]

[tool.hatch.envs.lint.scripts]
Expand Down Expand Up @@ -101,7 +102,7 @@ known-first-party = ["apricot"]

[tool.ruff.lint.pydocstyle]
convention = "google"
ignore-decorators = ["typing.overload"]
ignore-decorators = ["typing.override"]

[tool.mypy]
disallow_subclassing_any = false # allow subclassing of types from third-party libraries
Expand Down
Loading