|
1 | 1 | """Tests for dynamic and static attribute errors."""
|
2 | 2 |
|
3 | 3 | importimportlib
|
| 4 | +fromtypingimportType |
4 | 5 |
|
5 | 6 | importpytest
|
6 | 7 |
|
@@ -28,6 +29,23 @@ def test_util_alias_import_resolves() -> None:
|
28 | 29 | assertutilisgit.index.util
|
29 | 30 |
|
30 | 31 |
|
| 32 | +deftest_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 | +fromgit.index.utilimportTemporaryFileSwap |
| 37 | + |
| 38 | +defaccepts_tfs_type(t:Type[TemporaryFileSwap])->None: |
| 39 | +pass |
| 40 | + |
| 41 | +defrejects_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 | +assertgu_tfsisTemporaryFileSwap |
| 47 | + |
| 48 | + |
31 | 49 | deftest_util_alias_access_warns()->None:
|
32 | 50 | withpytest.deprecated_call()asctx:
|
33 | 51 | git.util
|
@@ -103,14 +121,3 @@ def test_private_module_alias_import_warns(self, name: str, fullname: str) -> No
|
103 | 121 | exec(f"from git import{name}")
|
104 | 122 |
|
105 | 123 | assertctx[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. |
|