You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This creates a git.diff.DiffConstants enumeration and makes the
git.diff.NULL_TREE and git.diff.Diffable.Index objects constants in
it. This allows them (including as an alternative in a union) to be
annotated as literals:
- Literal[DiffConstants.NULL_TREE]
- Literal[DIffConstants.INDEX]
Although the enumeration type must unfortunately be included in the
annotations as shown above (at least mypy requires this), using the
objects/values themselves does not require any code to change. So
this shouldn't break anything at runtime for code using GitPython,
unless it has relied on NULL_TREE being a direct instance of object,
or relied on Diffable.Index (all useful uses of which were also as
an opaque constant) being defined as a class.
More specifically, all the ways that NULL_TREE and Index could be
*accessed* before are still working, because:
- NULL_TREE is aliased at module level, where it was before.
It is also aliased at class level in Diffable, for consistency.
- INDEX is aliased at class level in Diffable, as Index, where it
was before. This way, Diffable.Index can still be used. It is
also aliased, in the same scope, as INDEX. Because it is, and in
effect has always been, a constant, the new INDEX spelling is
preferable. But there is no major disadvantage of the old Index
spelling, so in docstrings I have made no effort at this time to
discourage its use. (If GitPython ever uses all-caps identifiers
strictly as constants, then the clarity benefit of ensuring only
the INDEX version is used will be greater, and then it might make
sense to deprecate Index. However, this seems unlikely to happen
as it would be a breaking change, due to the way functions like
git.reset rebind Git.GIT_PYTHON_GIT_EXECUTABLE.) INDEX is also
aliased at module level, for consistency.
- NULL_TREE is still included in git.diff.__all__, causing it to be
recognized as public in git.diff and also to be accessible as an
attribute of the top-level git module (which currently uses
wildcard imports). For consistency, I have also included INDEX in
__all__.
- Because there is a benefit to being able to freely referene the
new DiffConstants enumeration in annotations (though in practice
this may mostly be to implementers of new Diffable subclasses), I
have also included DiffConstants in __all__. In addition, the
name DiffConstants (rather than, e.g., Constants) should avoid
confusion even if it ends up in another scope unexpectedly.
To avoid a situation where users/developers may erroneously think
these aliases are different from each other, I have documented the
situation in the docstrings for each, referring to the others.
(Sphinx does not automatically use the original docstring for an
aliased name introduced in this way, and there is also arguably a
clarity benefit to their differing wording, such as how each refers
*only* to the others.) Other docstings are also updated.
This commit completes the change begun in 2f5e258 before this,
resolving the one mypy error it added. But this does not complete
the larger change begun in 0e1df29:
- One of the effects of this change is to make it possible to
annotate precisely for NULL_TREE, either by using
Literal[DiffConstants.NULL_TREE] or consolidating it with the
Literal[DiffConstants.INDEX] alternative by including
DiffConstants in the union instead of either/both of them.
- But that is not yet done here, and when it is done for
Diffable.diff, the LSP issue in IndexFile.diff, which does not
currently accommodate NULL_TREE, will resurface (or, rather, be
rightly revealed by mypy, in a way that is specifically clear).
0 commit comments