|
29 | 29 | "GitCommandError", |
30 | 30 | "GitCommandNotFound", |
31 | 31 | "GitConfigParser", |
32 | | - "GitDB", |
33 | 32 | "GitError", |
34 | 33 | "HEAD", |
35 | 34 | "Head", |
|
40 | 39 | "IndexObject", |
41 | 40 | "InvalidDBRoot", |
42 | 41 | "InvalidGitRepositoryError", |
43 | | - "List", # Deprecated - import this from `typing` instead. |
44 | 42 | "LockFile", |
45 | 43 | "NULL_TREE", |
46 | 44 | "NoSuchPathError", |
47 | 45 | "ODBError", |
48 | 46 | "Object", |
49 | | - "Optional", # Deprecated - import this from `typing` instead. |
50 | 47 | "ParseError", |
51 | 48 | "PathLike", |
52 | 49 | "PushInfo", |
|
60 | 57 | "RepositoryDirtyError", |
61 | 58 | "RootModule", |
62 | 59 | "RootUpdateProgress", |
63 | | - "Sequence", # Deprecated - import from `typing`, or `collections.abc` in 3.9+. |
64 | 60 | "StageType", |
65 | 61 | "Stats", |
66 | 62 | "Submodule", |
67 | 63 | "SymbolicReference", |
68 | | - "TYPE_CHECKING", # Deprecated - import this from `typing` instead. |
69 | 64 | "Tag", |
70 | 65 | "TagObject", |
71 | 66 | "TagReference", |
72 | 67 | "Tree", |
73 | 68 | "TreeModifier", |
74 | | - "Tuple", # Deprecated - import this from `typing` instead. |
75 | | - "Union", # Deprecated - import this from `typing` instead. |
76 | 69 | "UnmergedEntriesError", |
77 | 70 | "UnsafeOptionError", |
78 | 71 | "UnsafeProtocolError", |
|
88 | 81 |
|
89 | 82 | __version__ = "git" |
90 | 83 |
|
91 | | -from typing import Any, List, Optional, Sequence, TYPE_CHECKING, Tuple, Union |
92 | | - |
93 | | -if TYPE_CHECKING: |
94 | | - from types import ModuleType |
95 | | - |
96 | | -import warnings |
| 84 | +from typing import Optional as _Optional |
97 | 85 |
|
98 | 86 | from git.util import to_hex_sha |
99 | 87 |
|
|
158 | 146 | DiffIndex, |
159 | 147 | Diffable, |
160 | 148 | ) |
161 | | - from git.db import GitCmdObjectDB, GitDB # @NoMove |
| 149 | + from git.db import GitCmdObjectDB # @NoMove |
162 | 150 | from git.cmd import Git # @NoMove |
163 | 151 | from git.repo import Repo # @NoMove |
164 | 152 | from git.remote import FetchInfo, PushInfo, Remote, RemoteProgress # @NoMove |
|
169 | 157 | IndexEntry, |
170 | 158 | IndexFile, |
171 | 159 | StageType, |
172 | | - # NOTE: This tells type checkers what util resolves to. We delete it, and it is |
173 | | - # really resolved by __getattr__, which warns. See below on what to use instead. |
174 | | - util, |
175 | 160 | ) |
176 | 161 | from git.util import ( # @NoMove |
177 | 162 | Actor, |
|
185 | 170 | raise ImportError("%s: %s" % (_exc.__class__.__name__, _exc)) from _exc |
186 | 171 |
|
187 | 172 |
|
188 | | -def _warned_import(message: str, fullname: str) -> "ModuleType": |
189 | | - import importlib |
190 | | - |
191 | | - warnings.warn(message, DeprecationWarning, stacklevel=3) |
192 | | - return importlib.import_module(fullname) |
193 | | - |
194 | | - |
195 | | -def _getattr(name: str) -> Any: |
196 | | - # TODO: If __version__ is made dynamic and lazily fetched, put that case right here. |
197 | | - |
198 | | - if name == "util": |
199 | | - return _warned_import( |
200 | | - "The expression `git.util` and the import `from git import util` actually " |
201 | | - "reference git.index.util, and not the git.util module accessed in " |
202 | | - '`from git.util import XYZ` or `sys.modules["git.util"]`. This potentially ' |
203 | | - "confusing behavior is currently preserved for compatibility, but may be " |
204 | | - "changed in the future and should not be relied on.", |
205 | | - fullname="git.index.util", |
206 | | - ) |
207 | | - |
208 | | - for names, prefix in ( |
209 | | - ({"head", "log", "reference", "symbolic", "tag"}, "git.refs"), |
210 | | - ({"base", "fun", "typ"}, "git.index"), |
211 | | - ): |
212 | | - if name not in names: |
213 | | - continue |
214 | | - |
215 | | - fullname = f"{prefix}.{name}" |
216 | | - |
217 | | - return _warned_import( |
218 | | - f"{__name__}.{name} is a private alias of {fullname} and subject to " |
219 | | - f"immediate removal. Use {fullname} instead.", |
220 | | - fullname=fullname, |
221 | | - ) |
222 | | - |
223 | | - raise AttributeError(f"module {__name__!r} has no attribute {name!r}") |
224 | | - |
225 | | - |
226 | | -if not TYPE_CHECKING: |
227 | | - # NOTE: The expression `git.util` gives git.index.util and `from git import util` |
228 | | - # imports git.index.util, NOT git.util. It may not be feasible to change this until |
229 | | - # the next major version, to avoid breaking code inadvertently relying on it. |
230 | | - # |
231 | | - # - If git.index.util *is* what you want, use (or import from) that, to avoid |
232 | | - # confusion. |
233 | | - # |
234 | | - # - To use the "real" git.util module, write `from git.util import ...`, or if |
235 | | - # necessary access it as `sys.modules["git.util"]`. |
236 | | - # |
237 | | - # Note also that `import git.util` technically imports the "real" git.util... but |
238 | | - # the *expression* `git.util` after doing so is still git.index.util! |
239 | | - # |
240 | | - # (This situation differs from that of other indirect-submodule imports that are |
241 | | - # unambiguously non-public and subject to immediate removal. Here, the public |
242 | | - # git.util module, though different, makes less discoverable that the expression |
243 | | - # `git.util` refers to a non-public attribute of the git module.) |
244 | | - # |
245 | | - # This had originally come about by a wildcard import. Now that all intended imports |
246 | | - # are explicit, the intuitive but potentially incompatible binding occurs due to the |
247 | | - # usual rules for Python submodule bindings. So for now we replace that binding with |
248 | | - # git.index.util, delete that, and let __getattr__ handle it and issue a warning. |
249 | | - # |
250 | | - # For the same runtime behavior, it would be enough to forgo importing util, and |
251 | | - # delete util as created naturally; __getattr__ would behave the same. But type |
252 | | - # checkers would not know what util refers to when accessed as an attribute of git. |
253 | | - del util |
254 | | - |
255 | | - # This is "hidden" to preserve static checking for undefined/misspelled attributes. |
256 | | - __getattr__ = _getattr |
257 | | - |
258 | 173 | # { Initialize git executable path |
259 | 174 |
|
260 | 175 | GIT_OK = None |
261 | 176 |
|
262 | 177 |
|
263 | | -def refresh(path: Optional[PathLike] = None) -> None: |
| 178 | +def refresh(path: _Optional[PathLike] = None) -> None: |
264 | 179 | """Convenience method for setting the git executable path. |
265 | 180 |
|
266 | 181 | :param path: |
|
0 commit comments