| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 86d0177 commit a0fa2bd
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,18 +28,41 @@ | |||
| 28 | 28 | # --------------------------------------------------------------------------- | |
| 29 | 29 | ||
| 30 | 30 | ||
| 31 | - # DEPRECATED attributes providing shortcuts to operating system checks based on os.name. | ||
| 32 | - # | ||
| 33 | - # These are deprecated because it is clearer, and helps avoid bugs, to write out the | ||
| 34 | - # os.name or sys.platform checks explicitly, especially in cases where it matters which | ||
| 35 | - # is used. For example, is_win is False on Cygwin, but is often assumed True. To detect | ||
| 36 | - # Cygwin, use sys.platform == "cygwin". (Also, in the past, is_darwin was unreliable.) | ||
| 37 | - # | ||
| 38 | 31 | is_win = os.name == "nt" | |
| 32 | + """Deprecated alias for ``os.name == "nt"`` to check for native Windows. | ||
| 33 | + | ||
| 34 | + This is deprecated because it is clearer to write out :attr:`os.name` or | ||
| 35 | + :attr:`sys.platform` checks explicitly, especially in cases where it matters which is | ||
| 36 | + used. | ||
| 37 | + | ||
| 38 | + :note: ``is_win`` is ``False`` on Cygwin, but is often wrongly assumed ``True``. To | ||
| 39 | + detect Cygwin, use ``sys.platform == "cygwin"``. | ||
| 40 | + """ | ||
| 41 | + | ||
| 39 | 42 | is_posix = os.name == "posix" | |
| 43 | + """Deprecated alias for ``os.name == "posix"`` to check for Unix-like ("POSIX") systems. | ||
| 44 | + | ||
| 45 | + This is deprecated because it clearer to write out :attr:`os.name` or | ||
| 46 | + :attr:`sys.platform` checks explicitly, especially in cases where it matters which is | ||
| 47 | + used. | ||
| 48 | + | ||
| 49 | + :note: For POSIX systems, more detailed information is available in | ||
| 50 | + :attr:`sys.platform`, while :attr:`os.name` is always ``"posix"`` on such systems, | ||
| 51 | + including macOS (Darwin). | ||
| 52 | + """ | ||
| 53 | + | ||
| 40 | 54 | is_darwin = sys.platform == "darwin" | |
| 55 | + """Deprecated alias for ``sys.platform == "darwin"`` to check for macOS (Darwin). | ||
| 56 | + | ||
| 57 | + This is deprecated because it clearer to write out :attr:`os.name` or | ||
| 58 | + :attr:`sys.platform` checks explicitly. | ||
| 59 | + | ||
| 60 | + :note: For macOS (Darwin), ``os.name == "posix"`` as in other Unix-like systems, while | ||
| 61 | + ``sys.platform == "darwin"`. | ||
| 62 | + """ | ||
| 41 | 63 | ||
| 42 | 64 | defenc = sys.getfilesystemencoding() | |
| 65 | + """The encoding used to convert between Unicode and bytes filenames.""" | ||
| 43 | 66 | ||
| 44 | 67 | ||
| 45 | 68 | @overload | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ | |||
| 4 | 4 | # 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/ | |
| 5 | 5 | ||
| 6 | 6 | import re | |
| 7 | + | ||
| 7 | 8 | from git.cmd import handle_process_output | |
| 8 | 9 | from git.compat import defenc | |
| 9 | 10 | from git.util import finalize_process, hex_to_bin | |
@@ -208,13 +209,15 @@ class DiffIndex(List[T_Diff]): | |||
| 208 | 209 | The class improves the diff handling convenience. | |
| 209 | 210 | """ | |
| 210 | 211 | ||
| 211 | - # Change type invariant identifying possible ways a blob can have changed: | ||
| 212 | - # A = Added | ||
| 213 | - # D = Deleted | ||
| 214 | - # R = Renamed | ||
| 215 | - # M = Modified | ||
| 216 | - # T = Changed in the type | ||
| 217 | 212 | change_type = ("A", "C", "D", "R", "M", "T") | |
| 213 | + """Change type invariant identifying possible ways a blob can have changed: | ||
| 214 | + | ||
| 215 | + * ``A`` = Added | ||
| 216 | + * ``D`` = Deleted | ||
| 217 | + * ``R`` = Renamed | ||
| 218 | + * ``M`` = Modified | ||
| 219 | + * ``T`` = Changed in the type | ||
| 220 | + """ | ||
| 218 | 221 | ||
| 219 | 222 | def iter_change_type(self, change_type: Lit_change_type) -> Iterator[T_Diff]: | |
| 220 | 223 | """ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -352,8 +352,8 @@ def stats(self) -> Stats: | |||
| 352 | 352 | def trailers(self) -> Dict[str, str]: | |
| 353 | 353 | """Get the trailers of the message as a dictionary | |
| 354 | 354 | ||
| 355 | - :note: This property is deprecated, please use either ``Commit.trailers_list`` | ||
| 356 | - or ``Commit.trailers_dict``. | ||
| 355 | + :note: This property is deprecated, please use either :attr:`trailers_list` or | ||
| 356 | + :attr:`trailers_dict``. | ||
| 357 | 357 | ||
| 358 | 358 | :return: | |
| 359 | 359 | Dictionary containing whitespace stripped trailer information. Only contains | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,9 +62,9 @@ class TraverseNT(NamedTuple): | |||
| 62 | 62 | T_TIobj = TypeVar("T_TIobj", bound="TraversableIterableObj") # For TraversableIterableObj.traverse() | |
| 63 | 63 | ||
| 64 | 64 | TraversedTup = Union[ | |
| 65 | - Tuple[Union["Traversable", None], "Traversable"], # For commit, submodule | ||
| 66 | - "TraversedTreeTup", | ||
| 67 | - ] # for tree.traverse() | ||
| 65 | + Tuple[Union["Traversable", None], "Traversable"], # For Commit, Submodule. | ||
| 66 | + "TraversedTreeTup", # For Tree.traverse(). | ||
| 67 | + ] | ||
| 68 | 68 | ||
| 69 | 69 | # -------------------------------------------------------------------- | |
| 70 | 70 | ||
@@ -380,11 +380,15 @@ class Tree:: (cls, Tree) -> Tuple[Tree, ...] | |||
| 380 | 380 | ||
| 381 | 381 | @abstractmethod | |
| 382 | 382 | def list_traverse(self, *args: Any, **kwargs: Any) -> Any: | |
| 383 | - """ """ | ||
| 383 | + """Traverse self and collect all items found. | ||
| 384 | + | ||
| 385 | + Calling this directly only the abstract base class, including via a ``super()`` | ||
| 386 | + proxy, is deprecated. Only overridden implementations should be called. | ||
| 387 | + """ | ||
| 384 | 388 | warnings.warn( | |
| 385 | 389 | "list_traverse() method should only be called from subclasses." | |
| 386 | - "Calling from Traversable abstract class will raise NotImplementedError in 3.1.20" | ||
| 387 | - "Builtin sublclasses are 'Submodule', 'Tree' and 'Commit", | ||
| 390 | + " Calling from Traversable abstract class will raise NotImplementedError in 4.0.0." | ||
| 391 | + " The concrete subclasses in GitPython itself are 'Commit', 'RootModule', 'Submodule', and 'Tree'.", | ||
| 388 | 392 | DeprecationWarning, | |
| 389 | 393 | stacklevel=2, | |
| 390 | 394 | ) | |
@@ -393,12 +397,14 @@ def list_traverse(self, *args: Any, **kwargs: Any) -> Any: | |||
| 393 | 397 | def _list_traverse( | |
| 394 | 398 | self, as_edge: bool = False, *args: Any, **kwargs: Any | |
| 395 | 399 | ) -> IterableList[Union["Commit", "Submodule", "Tree", "Blob"]]: | |
| 396 | - """ | ||
| 400 | + """Traverse self and collect all items found. | ||
| 401 | + | ||
| 397 | 402 | :return: IterableList with the results of the traversal as produced by | |
| 398 | - traverse() | ||
| 399 | - Commit -> IterableList['Commit'] | ||
| 400 | - Submodule -> IterableList['Submodule'] | ||
| 401 | - Tree -> IterableList[Union['Submodule', 'Tree', 'Blob']] | ||
| 403 | + :meth:`traverse`:: | ||
| 404 | + | ||
| 405 | + Commit -> IterableList['Commit'] | ||
| 406 | + Submodule -> IterableList['Submodule'] | ||
| 407 | + Tree -> IterableList[Union['Submodule', 'Tree', 'Blob']] | ||
| 402 | 408 | """ | |
| 403 | 409 | # Commit and Submodule have id.__attribute__ as IterableObj. | |
| 404 | 410 | # Tree has id.__attribute__ inherited from IndexObject. | |
@@ -421,11 +427,15 @@ def _list_traverse( | |||
| 421 | 427 | ||
| 422 | 428 | @abstractmethod | |
| 423 | 429 | def traverse(self, *args: Any, **kwargs: Any) -> Any: | |
| 424 | - """ """ | ||
| 430 | + """Iterator yielding items found when traversing self. | ||
| 431 | + | ||
| 432 | + Calling this directly on the abstract base class, including via a ``super()`` | ||
| 433 | + proxy, is deprecated. Only overridden implementations should be called. | ||
| 434 | + """ | ||
| 425 | 435 | warnings.warn( | |
| 426 | 436 | "traverse() method should only be called from subclasses." | |
| 427 | - "Calling from Traversable abstract class will raise NotImplementedError in 3.1.20" | ||
| 428 | - "Builtin sublclasses are 'Submodule', 'Tree' and 'Commit", | ||
| 437 | + " Calling from Traversable abstract class will raise NotImplementedError in 4.0.0." | ||
| 438 | + " The concrete subclasses in GitPython itself are 'Commit', 'RootModule', 'Submodule', and 'Tree'.", | ||
| 429 | 439 | DeprecationWarning, | |
| 430 | 440 | stacklevel=2, | |
| 431 | 441 | ) | |
@@ -441,7 +451,7 @@ def _traverse( | |||
| 441 | 451 | ignore_self: int = 1, | |
| 442 | 452 | as_edge: bool = False, | |
| 443 | 453 | ) -> Union[Iterator[Union["Traversable", "Blob"]], Iterator[TraversedTup]]: | |
| 444 | - """:return: Iterator yielding items found when traversing self | ||
| 454 | + """Iterator yielding items found when traversing self. | ||
| 445 | 455 | ||
| 446 | 456 | :param predicate: f(i,d) returns False if item i at depth d should not be | |
| 447 | 457 | included in the result. | |
@@ -471,18 +481,18 @@ def _traverse( | |||
| 471 | 481 | if True, return a pair of items, first being the source, second the | |
| 472 | 482 | destination, i.e. tuple(src, dest) with the edge spanning from source to | |
| 473 | 483 | destination | |
| 474 | - """ | ||
| 475 | 484 | ||
| 476 | - """ | ||
| 477 | - Commit -> Iterator[Union[Commit, Tuple[Commit, Commit]] | ||
| 478 | - Submodule -> Iterator[Submodule, Tuple[Submodule, Submodule]] | ||
| 479 | - Tree -> Iterator[Union[Blob, Tree, Submodule, | ||
| 480 | - Tuple[Union[Submodule, Tree], Union[Blob, Tree, Submodule]]] | ||
| 481 | - | ||
| 482 | - ignore_self=True is_edge=True -> Iterator[item] | ||
| 483 | - ignore_self=True is_edge=False --> Iterator[item] | ||
| 484 | - ignore_self=False is_edge=True -> Iterator[item] | Iterator[Tuple[src, item]] | ||
| 485 | - ignore_self=False is_edge=False -> Iterator[Tuple[src, item]] | ||
| 485 | + :return: Iterator yielding items found when traversing self:: | ||
| 486 | + | ||
| 487 | + Commit -> Iterator[Union[Commit, Tuple[Commit, Commit]] | ||
| 488 | + Submodule -> Iterator[Submodule, Tuple[Submodule, Submodule]] | ||
| 489 | + Tree -> Iterator[Union[Blob, Tree, Submodule, | ||
| 490 | + Tuple[Union[Submodule, Tree], Union[Blob, Tree, Submodule]]] | ||
| 491 | + | ||
| 492 | + ignore_self=True is_edge=True -> Iterator[item] | ||
| 493 | + ignore_self=True is_edge=False --> Iterator[item] | ||
| 494 | + ignore_self=False is_edge=True -> Iterator[item] | Iterator[Tuple[src, item]] | ||
| 495 | + ignore_self=False is_edge=False -> Iterator[Tuple[src, item]] | ||
| 486 | 496 | """ | |
| 487 | 497 | ||
| 488 | 498 | visited = set() | |
@@ -547,7 +557,7 @@ class Serializable(Protocol): | |||
| 547 | 557 | def _serialize(self, stream: "BytesIO") -> "Serializable": | |
| 548 | 558 | """Serialize the data of this object into the given data stream. | |
| 549 | 559 | ||
| 550 | - :note: A serialized object would ``_deserialize`` into the same object. | ||
| 560 | + :note: A serialized object would :meth:`_deserialize` into the same object. | ||
| 551 | 561 | ||
| 552 | 562 | :param stream: a file-like object | |
| 553 | 563 | ||
@@ -627,24 +637,24 @@ def traverse( | |||
| 627 | 637 | ignore_self: int = 1, | |
| 628 | 638 | as_edge: bool = False, | |
| 629 | 639 | ) -> Union[Iterator[T_TIobj], Iterator[Tuple[T_TIobj, T_TIobj]], Iterator[TIobj_tuple]]: | |
| 630 | - """For documentation, see util.Traversable._traverse()""" | ||
| 640 | + """For documentation, see :meth:`Traversable._traverse`.""" | ||
| 641 | + | ||
| 642 | + ## To typecheck instead of using cast: | ||
| 643 | + # | ||
| 644 | + # import itertools | ||
| 645 | + # from git.types import TypeGuard | ||
| 646 | + # def is_commit_traversed(inp: Tuple) -> TypeGuard[Tuple[Iterator[Tuple['Commit', 'Commit']]]]: | ||
| 647 | + # for x in inp[1]: | ||
| 648 | + # if not isinstance(x, tuple) and len(x) != 2: | ||
| 649 | + # if all(isinstance(inner, Commit) for inner in x): | ||
| 650 | + # continue | ||
| 651 | + # return True | ||
| 652 | + # | ||
| 653 | + # ret = super(Commit, self).traverse(predicate, prune, depth, branch_first, visit_once, ignore_self, as_edge) | ||
| 654 | + # ret_tup = itertools.tee(ret, 2) | ||
| 655 | + # assert is_commit_traversed(ret_tup), f"{[type(x) for x in list(ret_tup[0])]}" | ||
| 656 | + # return ret_tup[0] | ||
| 631 | 657 | ||
| 632 | - """ | ||
| 633 | - # To typecheck instead of using cast. | ||
| 634 | - import itertools | ||
| 635 | - from git.types import TypeGuard | ||
| 636 | - def is_commit_traversed(inp: Tuple) -> TypeGuard[Tuple[Iterator[Tuple['Commit', 'Commit']]]]: | ||
| 637 | - for x in inp[1]: | ||
| 638 | - if not isinstance(x, tuple) and len(x) != 2: | ||
| 639 | - if all(isinstance(inner, Commit) for inner in x): | ||
| 640 | - continue | ||
| 641 | - return True | ||
| 642 | - | ||
| 643 | - ret = super(Commit, self).traverse(predicate, prune, depth, branch_first, visit_once, ignore_self, as_edge) | ||
| 644 | - ret_tup = itertools.tee(ret, 2) | ||
| 645 | - assert is_commit_traversed(ret_tup), f"{[type(x) for x in list(ret_tup[0])]}" | ||
| 646 | - return ret_tup[0] | ||
| 647 | - """ | ||
| 648 | 658 | return cast( | |
| 649 | 659 | Union[Iterator[T_TIobj], Iterator[Tuple[Union[None, T_TIobj], T_TIobj]]], | |
| 650 | 660 | super()._traverse(predicate, prune, depth, branch_first, visit_once, ignore_self, as_edge), # type: ignore | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1233,10 +1233,10 @@ def __init__(cls, name: str, bases: Tuple, clsdict: Dict) -> None: | |||
| 1233 | 1233 | for base in bases: | |
| 1234 | 1234 | if type(base) is IterableClassWatcher: | |
| 1235 | 1235 | warnings.warn( | |
| 1236 | - f"GitPython Iterable subclassed by {name}. " | ||
| 1237 | - "Iterable is deprecated due to naming clash since v3.1.18" | ||
| 1238 | - " and will be removed in 3.1.20, " | ||
| 1239 | - "Use IterableObj instead \n", | ||
| 1236 | + f"GitPython Iterable subclassed by {name}." | ||
| 1237 | + " Iterable is deprecated due to naming clash since v3.1.18" | ||
| 1238 | + " and will be removed in 4.0.0." | ||
| 1239 | + " Use IterableObj instead.", | ||
| 1240 | 1240 | DeprecationWarning, | |
| 1241 | 1241 | stacklevel=2, | |
| 1242 | 1242 | ) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments