Skip to content

Commit 1d9e31a

Browse files
authored
fix: allow None for exc_tb in Traveller.__exit__ annotations (#974)
CPython calls __exit__(None, None, None) when a with block exits without an exception, so all three parameters must accept None. exc_type and exc_val were already optional on the travellers, but exc_tb was annotated TracebackType without | None, so a type checker infers the traveller is not a valid context manager and reports invalid-context-manager on with pendulum.travel_to(...). Annotate exc_tb as TracebackType | None in BaseTraveller.__exit__ and the time_machine-backed Traveller.__exit__ (the other Traveller subclasses inherit from BaseTraveller). Closes #973
1 parent b99bd14 commit 1d9e31a

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/pendulum/testing/traveller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __exit__(
4646
self,
4747
exc_type: type[BaseException] | None,
4848
exc_val: BaseException | None,
49-
exc_tb: TracebackType,
49+
exc_tb: TracebackType | None,
5050
) -> None: ...
5151

5252
def _not_implemented(self) -> NotImplementedError:
@@ -149,7 +149,7 @@ def __exit__(
149149
self,
150150
exc_type: type[BaseException] | None,
151151
exc_val: BaseException | None,
152-
exc_tb: TracebackType,
152+
exc_tb: TracebackType | None,
153153
) -> None:
154154
self.travel_back()
155155

0 commit comments

Comments
 (0)