Skip to content

Commit 927d563

Browse files
committed
pytest_plugin(refactor[types]): Extract env types to public TypeAliases
why: `_ENV` from `_internal/run.py` leaked into public API signatures, causing Sphinx to render its full expanded form (`Mapping[bytes, ...] | Mapping[str, ...]`) in the docs instead of a linkable name. `dict[str, str]` was also used ad-hoc in test annotations without a shared name. what: - Add `Env: t.TypeAlias = _ENV` as public alias for the subprocess env type; replace `env: _ENV | None` in all public signatures - Add `GitCommitEnvVars: t.TypeAlias = dict[str, str]` for the narrower git-commit env type; replace `git_commit_envvars: _ENV` in fixture parameters - Update test TYPE_CHECKING imports to use `GitCommitEnvVars`
1 parent ae3c53f commit 927d563

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

src/libvcs/pytest_plugin.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def vcs_user(vcs_name: str, vcs_email: str) -> str:
6666

6767

6868
@pytest.fixture(scope="session")
69-
def git_commit_envvars(vcs_name: str, vcs_email: str) -> _ENV:
69+
def git_commit_envvars(vcs_name: str, vcs_email: str) -> GitCommitEnvVars:
7070
"""Return environment variables for `git commit`.
7171
7272
For some reason, `GIT_CONFIG` via {func}`set_gitconfig` doesn't work for `git
@@ -266,6 +266,8 @@ def unique_repo_name(remote_repos_path: pathlib.Path, max_retries: int = 15) ->
266266

267267

268268
InitCmdArgs: t.TypeAlias = list[str] | None
269+
GitCommitEnvVars: t.TypeAlias = dict[str, str]
270+
Env: t.TypeAlias = _ENV
269271

270272

271273
class CreateRepoPostInitFn(t.Protocol):
@@ -274,7 +276,7 @@ class CreateRepoPostInitFn(t.Protocol):
274276
def __call__(
275277
self,
276278
remote_repo_path: pathlib.Path,
277-
env: _ENV | None = None,
279+
env: Env | None = None,
278280
) -> None:
279281
"""Ran after creating a repo from pytest fixture."""
280282
...
@@ -301,7 +303,7 @@ def _create_git_remote_repo(
301303
remote_repo_path: pathlib.Path,
302304
remote_repo_post_init: CreateRepoPostInitFn | None = None,
303305
init_cmd_args: InitCmdArgs = DEFAULT_GIT_REMOTE_REPO_CMD_ARGS,
304-
env: _ENV | None = None,
306+
env: Env | None = None,
305307
) -> pathlib.Path:
306308
if init_cmd_args is None:
307309
init_cmd_args = []
@@ -434,7 +436,7 @@ def fn(
434436

435437
def git_remote_repo_single_commit_post_init(
436438
remote_repo_path: pathlib.Path,
437-
env: _ENV | None = None,
439+
env: Env | None = None,
438440
) -> None:
439441
"""Post-initialization: Create a test git repo with a single commit."""
440442
testfile_filename = "testfile.test"
@@ -456,7 +458,7 @@ def git_remote_repo_single_commit_post_init(
456458
def git_remote_repo(
457459
create_git_remote_repo: CreateRepoPytestFixtureFn,
458460
gitconfig: pathlib.Path,
459-
git_commit_envvars: _ENV,
461+
git_commit_envvars: GitCommitEnvVars,
460462
) -> pathlib.Path:
461463
"""Copy the session-scoped Git repository to a temporary directory."""
462464
# TODO: Cache the effect of of this in a session-based repo
@@ -490,7 +492,7 @@ def _create_svn_remote_repo(
490492

491493
def svn_remote_repo_single_commit_post_init(
492494
remote_repo_path: pathlib.Path,
493-
env: _ENV | None = None,
495+
env: Env | None = None,
494496
) -> None:
495497
"""Post-initialization: Create a test SVN repo with a single commit."""
496498
assert remote_repo_path.exists()
@@ -610,7 +612,7 @@ def _create_hg_remote_repo(
610612

611613
def hg_remote_repo_single_commit_post_init(
612614
remote_repo_path: pathlib.Path,
613-
env: _ENV | None = None,
615+
env: Env | None = None,
614616
) -> None:
615617
"""Post-initialization: Create a test mercurial repo with a single commit."""
616618
testfile_filename = "testfile.test"
@@ -787,7 +789,7 @@ def add_doctest_fixtures(
787789
doctest_namespace: dict[str, t.Any],
788790
tmp_path: pathlib.Path,
789791
set_home: pathlib.Path,
790-
git_commit_envvars: _ENV,
792+
git_commit_envvars: GitCommitEnvVars,
791793
hgconfig: pathlib.Path,
792794
create_git_remote_repo: CreateRepoPytestFixtureFn,
793795
create_svn_remote_repo: CreateRepoPytestFixtureFn,

tests/cmd/test_git.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from libvcs.cmd import git
1313

1414
if t.TYPE_CHECKING:
15-
from libvcs.pytest_plugin import CreateRepoPytestFixtureFn
15+
from libvcs.pytest_plugin import CreateRepoPytestFixtureFn, GitCommitEnvVars
1616
from libvcs.sync.git import GitSync
1717

1818

@@ -2287,7 +2287,7 @@ def test_reflog_entry_delete(git_repo: GitSync) -> None:
22872287
@pytest.fixture
22882288
def submodule_repo(
22892289
tmp_path: pathlib.Path,
2290-
git_commit_envvars: dict[str, str],
2290+
git_commit_envvars: GitCommitEnvVars,
22912291
set_gitconfig: pathlib.Path,
22922292
) -> git.Git:
22932293
"""Create a git repository to use as a submodule source."""

tests/test_pytest_plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
if t.TYPE_CHECKING:
1616
import pathlib
1717

18-
from libvcs.pytest_plugin import CreateRepoPytestFixtureFn
18+
from libvcs.pytest_plugin import CreateRepoPytestFixtureFn, GitCommitEnvVars
1919
from libvcs.sync.git import GitSync
2020

2121

@@ -265,7 +265,7 @@ def test_gitconfig_submodule_file_protocol(
265265
def test_git_repo_fixture_submodule_file_protocol(
266266
git_repo: GitSync,
267267
create_git_remote_repo: CreateRepoPytestFixtureFn,
268-
git_commit_envvars: dict[str, str],
268+
git_commit_envvars: GitCommitEnvVars,
269269
user_path: pathlib.Path,
270270
monkeypatch: pytest.MonkeyPatch,
271271
) -> None:

0 commit comments

Comments
 (0)