Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f6060df

Browse filesBrowse files
committed
Add GitMeta alias
Hopefully no one will ever need it.
1 parent 8327b45 commit f6060df
Copy full SHA for f6060df

File tree

1 file changed

+27
-1
lines changed
Filter options

1 file changed

+27
-1
lines changed

‎git/cmd.py

Copy file name to clipboardExpand all lines: git/cmd.py
+27-1Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from __future__ import annotations
77

8-
__all__ = ["Git"]
8+
__all__ = ["GitMeta", "Git"]
99

1010
import contextlib
1111
import io
@@ -354,6 +354,32 @@ def __setattr(cls, name: str, value: Any) -> Any:
354354
__setattr__ = __setattr
355355

356356

357+
GitMeta = _GitMeta
358+
"""Alias of :class:`Git`'s metaclass, whether it is :class:`type` or a custom metaclass.
359+
360+
Whether the :class:`Git` class has the default :class:`type` as its metaclass or uses a
361+
custom metaclass is not documented and may change at any time. This statically checkable
362+
metaclass alias is equivalent at runtime to ``type(Git)``. This should almost never be
363+
used. Code that benefits from it is likely to be remain brittle even if it is used.
364+
365+
In view of the :class:`Git` class's intended use and :class:`Git` objects' dynamic
366+
callable attributes representing git subcommands, it rarely makes sense to inherit from
367+
:class:`Git` at all. Using :class:`Git` in multiple inheritance can be especially tricky
368+
to do correctly. Attempting uses of :class:`Git` where its metaclass is relevant, such
369+
as when a sibling class has an unrelated metaclass and a shared lower bound metaclass
370+
might have to be introduced to solve a metaclass conflict, is not recommended.
371+
372+
:note:
373+
The correct static type of the :class:`Git` class itself, and any subclasses, is
374+
``Type[Git]``. (This can be written as ``type[Git]`` in Python 3.9 later.)
375+
376+
:class:`GitMeta` should never be used in any annotation where ``Type[Git]`` is
377+
intended or otherwise possible to use. This alias is truly only for very rare and
378+
inherently precarious situations where it is necessary to deal with the metaclass
379+
explicitly.
380+
"""
381+
382+
357383
class Git(metaclass=_GitMeta):
358384
"""The Git class manages communication with the Git binary.
359385

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.