Skip to content

Commit 8280771

Browse files
committed
rfctr: add type-stubs for behave
1 parent 08ab7e6 commit 8280771

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

features/steps/helpers.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import os
44

55

6-
def absjoin(*paths):
6+
def absjoin(*paths: str) -> str:
77
return os.path.abspath(os.path.join(*paths))
88

99

10-
thisdir = os.path.split(__file__)[0]
11-
scratch_dir = absjoin(thisdir, "../_scratch")
10+
thisdir: str = os.path.split(__file__)[0]
11+
scratch_dir: str = absjoin(thisdir, "../_scratch")
1212

1313
# scratch output docx file -------------
14-
saved_docx_path = absjoin(scratch_dir, "test_out.docx")
14+
saved_docx_path: str = absjoin(scratch_dir, "test_out.docx")
1515

1616
bool_vals = {"True": True, "False": False}
1717

@@ -24,15 +24,11 @@ def absjoin(*paths):
2424
}
2525

2626

27-
def test_docx(name):
28-
"""
29-
Return the absolute path to test .docx file with root name `name`.
30-
"""
27+
def test_docx(name: str):
28+
"""Return the absolute path to test .docx file with root name `name`."""
3129
return absjoin(thisdir, "test_files", "%s.docx" % name)
3230

3331

34-
def test_file(name):
35-
"""
36-
Return the absolute path to file with `name` in test_files directory
37-
"""
32+
def test_file(name: str):
33+
"""Return the absolute path to file with `name` in test_files directory"""
3834
return absjoin(thisdir, "test_files", "%s" % name)

pyrightconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"pythonVersion": "3.7",
1414
"reportImportCycles": true,
1515
"reportUnnecessaryCast": true,
16+
"reportUnnecessaryTypeIgnoreComment": true,
17+
"stubPath": "./typings",
1618
"typeCheckingMode": "strict",
1719
"useLibraryCodeForTypes": false,
1820
"verboseOutput": true

typings/behave/__init__.pyi

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from __future__ import annotations
2+
3+
from typing import Callable
4+
5+
from typing_extensions import Concatenate, ParamSpec, TypeAlias
6+
7+
from .runner import Context
8+
9+
_P = ParamSpec("_P")
10+
11+
_ArgsStep: TypeAlias = Callable[Concatenate[Context, _P], None]
12+
_NoArgsStep: TypeAlias = Callable[[Context], None]
13+
14+
_Step: TypeAlias = _NoArgsStep | _ArgsStep[str]
15+
16+
def given(phrase: str) -> Callable[[_Step], _Step]: ...
17+
def when(phrase: str) -> Callable[[_Step], _Step]: ...
18+
def then(phrase: str) -> Callable[[_Step], _Step]: ...

typings/behave/runner.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from types import SimpleNamespace
2+
3+
class Context(SimpleNamespace): ...

0 commit comments

Comments
 (0)