Skip to content

Commit 464b5cc

Browse files
perrygoybandophahita
authored andcommitted
add Path typing to Narrator and Adapter.
1 parent 0f6a9b5 commit 464b5cc

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

screenpy/narration/narrator.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
if TYPE_CHECKING:
2121
from collections.abc import Generator
2222
from contextlib import AbstractContextManager
23+
from pathlib import Path
2324
from typing import Any, Callable, Union
2425

2526
from screenpy.protocols import Adapter
@@ -246,8 +247,10 @@ def explains_the_error(self, exc: Exception) -> None:
246247
for adapter in self.adapters:
247248
adapter.error(exc)
248249

249-
# ANN401 ignored here to allow for new adapters to use any kwargs.
250-
def attaches_a_file(self, filepath: str, **kwargs: Any) -> None: # noqa: ANN401
250+
# ANN401 ignored here to allow for adapters to use needed kwargs.
251+
def attaches_a_file(
252+
self, filepath: Path | str, **kwargs: Any # noqa: ANN401
253+
) -> None:
251254
"""Attach a file for the various adapters."""
252255
for adapter in self.adapters:
253256
adapter.attach(filepath, **kwargs)

screenpy/narration/stdout_adapter/stdout_adapter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
if TYPE_CHECKING:
1818
from collections.abc import Generator
19+
from pathlib import Path
1920

2021
from typing_extensions import ParamSpec
2122

@@ -147,6 +148,6 @@ def error(self, exc: Exception) -> None:
147148
self.handled_exception = exc
148149

149150
# ANN401 ignored here to allow for new adapters to use any kwargs.
150-
def attach(self, filepath: str, **__: Any) -> None: # noqa: ANN401
151+
def attach(self, filepath: Path | str, **__: Any) -> None: # noqa: ANN401
151152
"""Log a mention of an attached file."""
152153
self.manager.log(f"See reference file: {filepath}")

screenpy/protocols.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
if TYPE_CHECKING:
1717
from collections.abc import Generator
18+
from pathlib import Path
1819
from typing import Any, Callable
1920

2021
from hamcrest.core.base_matcher import Matcher
@@ -130,7 +131,7 @@ def error(self, exc: Exception) -> None:
130131
"""React to an exception being thrown, probably during a beat."""
131132

132133
# ANN401 ignored here to allow for new adapters to use any kwargs.
133-
def attach(self, filepath: str, **kwargs: Any) -> None: # noqa: ANN401
134+
def attach(self, filepath: Path | str, **kwargs: Any) -> None: # noqa: ANN401
134135
"""Handle attaching a file.
135136
136137
Pass keyword arguments for specific adapters' needs.

0 commit comments

Comments
 (0)