Skip to content

Commit

Permalink
Fixed type annotation for ACMEClient.__aenter__. ACMEClient.from_stat…
Browse files Browse the repository at this point in the history
…e() now returns a proper subclass
  • Loading branch information
dvolodin7 committed Nov 16, 2023
1 parent fb064e9 commit 02a3c5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
7 changes: 4 additions & 3 deletions src/gufo/acme/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

BAD_REQUEST = 400
T = TypeVar("T")
CT = TypeVar("CT", bound="ACMEClient")


class ACMEClient(object):
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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"),
Expand Down

0 comments on commit 02a3c5b

Please sign in to comment.