Skip to content

Commit

Permalink
Fix git.objects.__all__ and make submodules explicit
Browse files Browse the repository at this point in the history
The submodules being made explicit here are of course Python
submodules, not git submodules.

The git.objects.submodule Python submodule (which is *about* git
submodules) is made explicit here (as are the names imported from
that Python submodule's own Python submodules) along with the other
Python submodules of git.objects.

Unlike some other submodules, but like the top-level git module
until gitpython-developers#1659, git.objects already defined __all__ but it was
dynamically constructed. As with git.__all__ previously (as noted
in gitpython-developers#1859), I have used https://github.com/EliahKagan/deltall here
to check that it is safe, sufficient, and probably necessary to
replace this dynamically constructed __all__ with a literal list of
strings in which all of the original elements are included. See:
https://gist.github.com/EliahKagan/e627603717ca5f9cafaf8de9d9f27ad7

Running the modattrs.py script, and diffing against the output from
before the current import refactoring began, reveals two changes to
module contents as a result of the change here:

- git.objects no longer contains `inspect`, which it imported just
  to build the dynamically constructed __all__. Because this was
  not itself included in that __all__ or otherwise made public or
  used out of git.objects, that is okay. This is exactly analogous
  to the situation in 8197e90, which removed it from the top-level
  git module after gitpython-developers#1659.

- The top-level git module now has has new attributes blob, commit,
  submodule, and tree, aliasing the corresponding modules. This
  has happened as a result of them being put in git.objects.__all__
  along with various names imported from them. (As noted in some
  prior commits, there are tradeoffs associated with doing this,
  and it may be that such elements of __all__ should be removed,
  here and elsewhere.)
  • Loading branch information
EliahKagan committed Mar 18, 2024
1 parent 01c95eb commit f89d065
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions git/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,30 @@

"""Import all submodules' main classes into the package space."""

import inspect
__all__ = [
"base",
"blob",
"commit",
"submodule",
"tag",
"tree",
"IndexObject",
"Object",
"Blob",
"Commit",
"Submodule",
"UpdateProgress",
"RootModule",
"RootUpdateProgress",
"TagObject",
"Tree",
"TreeModifier",
]

from .base import * # noqa: F403
from .blob import * # noqa: F403
from .commit import * # noqa: F403
from .submodule.base import * # noqa: F403
from .submodule.root import * # noqa: F403
from .tag import * # noqa: F403
from .tree import * # noqa: F403

# Must come after submodule was made available.
__all__ = [name for name, obj in locals().items() if not (name.startswith("_") or inspect.ismodule(obj))]
from .base import IndexObject, Object
from .blob import Blob
from .commit import Commit
from .submodule.base import Submodule, UpdateProgress
from .submodule.root import RootModule, RootUpdateProgress
from .tag import TagObject
from .tree import Tree, TreeModifier

0 comments on commit f89d065

Please sign in to comment.