Skip to content

Commit 99e6eb1

Browse files
authored
Merge pull request #3271 from python-trio/default-cancelreason
Added default value for the "source" parameter in the trio.Cancelled initializer
2 parents 4ff5c30 + d7125ac commit 99e6eb1

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/trio/_core/_exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class Cancelled(BaseException, metaclass=NoPublicConstructor):
8282
8383
"""
8484

85-
source: CancelReasonLiteral
85+
source: CancelReasonLiteral = "unknown"
8686
# repr(Task), so as to avoid gc troubles from holding a reference
8787
source_task: str | None = None
8888
reason: str | None = None
@@ -114,7 +114,7 @@ def __reduce__(self) -> tuple[Callable[[], Cancelled], tuple[()]]:
114114
def _create(
115115
cls,
116116
*,
117-
source: CancelReasonLiteral,
117+
source: CancelReasonLiteral = "unknown",
118118
source_task: str | None = None,
119119
reason: str | None = None,
120120
) -> Self: ...

src/trio/_core/_tests/test_cancelled.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
def test_Cancelled_init() -> None:
1616
with pytest.raises(TypeError, match=r"^trio.Cancelled has no public constructor$"):
17-
raise Cancelled # type: ignore[call-arg]
17+
raise Cancelled
1818

1919
with pytest.raises(TypeError, match=r"^trio.Cancelled has no public constructor$"):
2020
Cancelled(source="explicit")

0 commit comments

Comments
 (0)