diff --git a/CHANGELOG.md b/CHANGELOG.md index 11103b7..32e717d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 To see unreleased changes, please see the [CHANGELOG on the master branch](https://github.com/gufolabs/gufo_acme/blob/master/CHANGELOG.md) guide. +## [Unreleased] + +## Fixed + +* Fixed `ACMEClient.from_state()` to return a proper subclass. +* Fixed type annotation for `ACMEClient.__aenter__()` in subclasses. + ## 0.1.0 - 2023-11-15 * Initial release. \ No newline at end of file diff --git a/src/gufo/acme/client.py b/src/gufo/acme/client.py index 78f3c08..27f775f 100644 --- a/src/gufo/acme/client.py +++ b/src/gufo/acme/client.py @@ -62,6 +62,7 @@ BAD_REQUEST = 400 T = TypeVar("T") +CT = TypeVar("CT", bound="ACMEClient") class ACMEClient(object): @@ -131,7 +132,7 @@ def __init__( self._timeout = timeout or self.DEFAULT_TIMEOUT self._user_agent = user_agent or f"Gufo ACME/{__version__}" - async def __aenter__(self: "ACMEClient") -> "ACMEClient": + async def __aenter__(self: CT) -> CT: """ An asynchronous context manager. @@ -1147,7 +1148,7 @@ def get_state(self: "ACMEClient") -> bytes: return json.dumps(state, indent=2).encode() @classmethod - def from_state(cls: Type["ACMEClient"], state: bytes) -> "ACMEClient": + def from_state(cls: Type[CT], state: bytes) -> CT: """ Restore ACMEClient from the state. @@ -1162,7 +1163,7 @@ def from_state(cls: Type["ACMEClient"], state: bytes) -> "ACMEClient": New ACMEClient instance. """ s = json.loads(state) - return ACMEClient( + return cls( s["directory"], key=JWKRSA.fields_from_json(s["key"]), account_url=s.get("account_url"),