Refactor Git.{AutoInterrupt,CatFileContentStream} nesting by EliahKagan · Pull Request #2037 · gitpython-developers/GitPython
Repository navigation
Refactor Git.{AutoInterrupt,CatFileContentStream} nesting - #2037
Merged
Byron merged 1 commit into gitpython-developers:main from EliahKagan:flatten Jun 7, 2025
Merged
Refactor Git.{AutoInterrupt,CatFileContentStream} nesting #2037 Byron merged 1 commit into gitpython-developers:main from EliahKagan:flatten
Conversation
EliahKagan commented Jun 7, 2025 · edited Loading
Copy link Copy Markdown
Member
This makes Git.AutoInterrupt and Git.CatFileContentStream transparent aliases to top-level nonpublic _AutoInterrupt and _CatFileContentStream classes in the cmd module.
This does not change the "public" interface. It also does not change metadata relevant to documentation: the __name__ and __qualname__ attributes are set explicitly to the values they had before when these classes were defined nested, so that Sphinx continues to document them (and to do so in full) in Git and as Git.AutoInterrupt and Git.CatFileContentStream.
The purpose of this is to increase readability. The Git class is big and complex, with a number of long members and various forms of nesting. Since these two classes can be understood even without reading the code of the Git class, moving the definitions out of the Git class into top-level nonpublic classes will hopefully increase readability and help with maintenance.
I originally intended this as just the first commit of several. But I realized that change is probably the only one that might be controversial. So I figured I'd open a PR for it by itself.
In my view:
- The flatter layout and physical separation makes for easier reading and emphasizes that, even as they are nested classes of the
Gitclass as far as the interface is concerned, these classes are uses by theGitand do not themselves use theGitclass. - The conceptual burden of setting
__name__and__qualname__to make Sphinx continue working as desired (while still having the metadata at runtime the same as Sphinx claims) is not too big of a conceptual burden.
But whether this is better is a subjective question, so I figured it would be good to get a review.
I have verified that the intended effect in Sphinx documentation--the effect that the classes continue to be presented, in full, as nested classes of Git, just as they may (and should!) continue to be used when they are accessed both within GitPython and by other code that uses GitPython--is what we get. Specifically:
- I observed this locally, and
- It can be seen in the readthedocs cloud build for this PR, for
Git.AutoInterruptandGit.CatFileContentStream. (They can be compared to the latest release versions of theGit.AutoInterruptandGit.CatFileContentStreamclasses.)
Refactor Git.{AutoInterrupt,CatFileContentStream} nesting
5a8a405
This makes `Git.AutoInterrupt` and `Git.CatFileContentStream` transparent aliases to top-level nonpublic `_AutoInterrupt` and `_CatFileContentStream` classes in the `cmd` module. This does not change the "public" interface. It also does not change metadata relevant to documentation: the `__name__` and `__qualname__` attributes are set explicitly to the values they had before when these classes were defined nested, so that Sphinx continues to document them (and to do so in full) in `Git` and as `Git.AutoInterrupt` and `Git.CatFileContentStream`. The purpose of this is to increase readability. The `Git` class is big and complex, with a number of long members and various forms of nesting. Since these two classes can be understood even without reading the code of the `Git` class, moving the definitions out of the `Git` class into top-level nonpublic classes will hopefully increase readability and help with maintenance.EliahKagan force-pushed the flatten branch from
eb07ccb to
5a8a405
Compare
June 7, 2025 06:00 EliahKagan marked this pull request as ready for review June 7, 2025 06:06 EliahKagan requested a review from Byron June 7, 2025 06:06 Byron approved these changes Jun 7, 2025
View reviewed changes
Byron left a comment
Copy link Copy Markdown
Member
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
Thanks a lot, this makes perfect sense.
Thanks also for double-checking that the documentation is still working as it did before.
Please note that I didn't validate that the removed and added portions are still the same in the interest of time.
Byron merged commit1e463d4
into
gitpython-developers : main
Jun 7, 2025
EliahKagan
deleted the
flatten
branch
June 7, 2025 06:23
EliahKagan commented Jun 7, 2025 · edited Loading
Copy link Copy Markdown
Member
Author
No problem! It was not at all obvious to me what Sphinx would do if I had not modified the metadata. (So I tried that first, but only locally, without committing the change.) If that had turned out not to be necessary for Sphinx, then I would not be sure whether it would be best to do it or not, since I think the interface is really the same either way. In any case, I think it's better to modify the metadata like this and automatically keep the documentation, than not to do so and have Sphinx treat them as nonpublic and not emit documentation for them at all.
It looks like some common techniques don't work here, due to a combination of changed indentation, moving the code, changing the lines at the top of the code that is moved (to I've double-checked it just now by:
It looks right, with only the new, conceptually changed (e.g. adding |
Start on fixing AutoInterrupt/CatFileContentStream aliases
c6d16d0
This uses `TypeAlias` from the `typing` module, to make it so the assignment statments introduced in gitpython-developers#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 gitpython-developers#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.This was referenced Jun 7, 2025 Fix Git.{AutoInterrupt,CatFileContentStream} static typing #2039 Merged Fix CI
mypy command on free-threaded Python
#2040
Merged
Sign up for free
to join this conversation on GitHub .
Already have an account?
Sign in to comment