Skip to content

Fix Git.{AutoInterrupt,CatFileContentStream} static typing #2039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 7, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Start on fixing AutoInterrupt/CatFileContentStream aliases
This uses `TypeAlias` from the `typing` module, to make it so the
assignment statments introduced in #2037 (to set `Git.AutoInterrupt`
and `Git.CatFileContentStream` to nonpublic module-level
implementations `_AutoInterrupt` and `_CatFileContentStream`) are
treated by `mypy` as type aliases rather than as class variables.

For details on the problem this partially fixes, see #2038 and:
https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases

The fix won't work in this form, however, because it attempts to
import `TypeAlias` unconditionally from the standard-library
`typing` module, which only gained it in Python 3.10.
  • Loading branch information
EliahKagan committed Jun 7, 2025
commit c6d16d01c54d45be20de40dedae4e9471b96c8ab
5 changes: 3 additions & 2 deletions git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
TYPE_CHECKING,
TextIO,
Tuple,
TypeAlias,
Union,
cast,
overload,
Expand Down Expand Up @@ -952,9 +953,9 @@ def check_unsafe_options(cls, options: List[str], unsafe_options: List[str]) ->
f"{unsafe_option} is not allowed, use `allow_unsafe_options=True` to allow it."
)

AutoInterrupt = _AutoInterrupt
AutoInterrupt: TypeAlias = _AutoInterrupt

CatFileContentStream = _CatFileContentStream
CatFileContentStream: TypeAlias = _CatFileContentStream

def __init__(self, working_dir: Union[None, PathLike] = None) -> None:
"""Initialize this instance with:
Expand Down
Loading