Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite133018

Browse files
committed
Broaden cygpath parameter annotation
To fix a mypy error in Repo.__init__ where the epath variable,which can sometimes be a os.PathLike[str], does not match the strannotation for cygpath's path parameter, even though cygwinimmediately calls str on that parameter.Pulling most of cygpath out into a new helper function is to helpmypy correctly infer that the type of path is still compatible withthe return type of str, when it is used in the return statement.I'm not sure this change is really the best solution at this time,because while it fixes the mypy error (without creating a new one),and cygpath is not listed in __all__, the docstring of advises tocall Git.polish_url instead of cygpath. That method is public,annotates its parameter as str, and should not have its annotationbroadened without considernig if it makes sense to do so or if itsdocstring needs to be updated.So either the cygpath docstring should be updated or this changeshould be undone and a different approach used to fix the typeerror in Repo.__init__.
1 parentf1cc1fe commite133018

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

‎git/util.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,7 @@ def _cygexpath(drive: Optional[str], path: str) -> str:
404404
)
405405

406406

407-
defcygpath(path:str)->str:
408-
"""Use :meth:`git.cmd.Git.polish_url` instead, that works on any environment."""
409-
path=str(path)# Ensure is str and not AnyPath.
407+
def_cygpath(path:str)->str:
410408
# Fix to use Paths when 3.5 dropped. Or to be just str if only for URLs?
411409
ifnotpath.startswith(("/cygdrive","//","/proc/cygdrive")):
412410
forregex,parser,recursein_cygpath_parsers:
@@ -422,6 +420,11 @@ def cygpath(path: str) -> str:
422420
returnpath
423421

424422

423+
defcygpath(path:PathLike)->str:
424+
"""Use :meth:`git.cmd.Git.polish_url` instead, that works on any environment."""
425+
return_cygpath(str(path))# Ensure is str and not AnyPath.
426+
427+
425428
_decygpath_regex=re.compile(r"(?:/proc)?/cygdrive/(\w)(/.*)?")
426429

427430

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp