Skip to content

Commit ebcfced

Browse files
committed
Fix and deprecate Lit_commit_ish
It would be a breaking change to keep Lit_commit_ish undefined, so this brings it back, but with a narrowed definition for consistency with the corrected Commit_ish, and deprecated, with instructions on what to use instead. (This also improves import sorting in the same module.)
1 parent 93d19dc commit ebcfced

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

git/types.py

+17-20
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,38 @@
44
import os
55
import sys
66
from typing import ( # noqa: F401
7+
Any,
8+
Callable,
79
Dict,
810
NoReturn,
11+
Optional,
912
Sequence as Sequence,
1013
Tuple,
11-
Union,
12-
Any,
13-
Optional,
14-
Callable,
1514
TYPE_CHECKING,
1615
TypeVar,
16+
Union,
1717
)
1818

1919
if sys.version_info >= (3, 8):
2020
from typing import ( # noqa: F401
2121
Literal,
22-
TypedDict,
2322
Protocol,
2423
SupportsIndex as SupportsIndex,
24+
TypedDict,
2525
runtime_checkable,
2626
)
2727
else:
2828
from typing_extensions import ( # noqa: F401
2929
Literal,
30+
Protocol,
3031
SupportsIndex as SupportsIndex,
3132
TypedDict,
32-
Protocol,
3333
runtime_checkable,
3434
)
3535

3636
if TYPE_CHECKING:
37-
from git.repo import Repo
3837
from git.objects import Commit, Tree, TagObject, Blob
38+
from git.repo import Repo
3939

4040
PathLike = Union[str, "os.PathLike[str]"]
4141
"""A :class:`str` (Unicode) based file or directory path."""
@@ -126,22 +126,19 @@
126126
gitglossary(7) on "object type": https://git-scm.com/docs/gitglossary#def_object_type
127127
"""
128128

129+
Lit_commit_ish = Literal["commit", "tag"]
130+
"""Deprecated. Type of literal strings identifying sometimes-commitish git object types.
129131
130-
# FIXME: After replacing the one use with GitObjectTypeString, define Lit_commit_ish
131-
# somehow (it is a breaking change to remove it entirely). Maybe deprecate it.
132-
Lit_old_commit_ish = Literal["commit", "tag", "blob", "tree"]
133-
"""Literal strings identifying concrete :class:`~git.objects.base.Object` subtypes
134-
representing git object types.
135-
136-
See the :class:`Object.type <git.objects.base.Object.type>` attribute.
132+
Prior to a bugfix, this type had been defined more broadly. Any usage is in practice
133+
ambiguous and likely to be incorrect. Instead of this type:
137134
138-
:note:
139-
See also :class:`Old_commit_ish`, a union of the the :class:`~git.objects.base.Object`
140-
subtypes associated with these literal strings.
135+
* For the type of the string literals associated with :class:`Commit_ish`, use
136+
``Literal["commit", "tag"]`` or create a new type alias for it. That is equivalent to
137+
this type as currently defined.
141138
142-
:note:
143-
As noted in :class:`Old_commit_ish`, this is not limited to types of git objects that
144-
are actually commit-ish.
139+
* For the type of all four string literals associated with :class:`AnyGitObject`, use
140+
:class:`GitObjectTypeString`. That is equivalent to the old definition of this type
141+
prior to the bugfix.
145142
"""
146143

147144
# Config_levels ---------------------------------------------------------

0 commit comments

Comments
 (0)