Skip to content

Commit aee7078

Browse files
committed
Test resolution into git.index.util using git.util
1 parent f39bbb5 commit aee7078

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

test/deprecation/test_attributes.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for dynamic and static attribute errors."""
22

33
import importlib
4+
from typing import Type
45

56
import pytest
67

@@ -28,6 +29,23 @@ def test_util_alias_import_resolves() -> None:
2829
assert util is git.index.util
2930

3031

32+
def test_util_alias_members_resolve() -> None:
33+
"""git.index.util members can be accessed via git.util, and mypy recognizes it."""
34+
# TODO: When typing_extensions is made a test dependency, use assert_type for this.
35+
gu_tfs = git.util.TemporaryFileSwap
36+
from git.index.util import TemporaryFileSwap
37+
38+
def accepts_tfs_type(t: Type[TemporaryFileSwap]) -> None:
39+
pass
40+
41+
def rejects_tfs_type(t: Type[git.Git]) -> None:
42+
pass
43+
44+
accepts_tfs_type(gu_tfs)
45+
rejects_tfs_type(gu_tfs) # type: ignore[arg-type]
46+
assert gu_tfs is TemporaryFileSwap
47+
48+
3149
def test_util_alias_access_warns() -> None:
3250
with pytest.deprecated_call() as ctx:
3351
git.util
@@ -103,14 +121,3 @@ def test_private_module_alias_import_warns(self, name: str, fullname: str) -> No
103121
exec(f"from git import {name}")
104122

105123
assert ctx[0].message.args[0].endswith(f"Use {fullname} instead.")
106-
107-
108-
reveal_type(git.util.git_working_dir)
109-
110-
# FIXME: Add one or more test cases that access something like git.util.git_working_dir
111-
# to verify that it is available, and also use assert_type on it to ensure mypy knows
112-
# that accesses to expressions of the form git.util.XYZ resolve to git.index.util.XYZ.
113-
#
114-
# It may be necessary for GitPython, in git/__init__.py, to import util from git.index
115-
# explicitly before (still) deleting the util global, in order for mypy to know what is
116-
# going on. Also check pyright.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy