-
-
Notifications
You must be signed in to change notification settings - Fork 894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better document IterableObj.iter_items and improve some subclasses #1780
Commits on Dec 22, 2023
-
Remove explicit PushInfo/FetchInfo inheritance from object
I had missed these in f78587f (gitpython-developers#1725).
Configuration menu - View commit details
-
Copy full SHA for 53e7383 - Browse repository at this point
Copy the full SHA 53e7383View commit details -
Add tests for current Submodule.iter_items behavior
Where the behavior is intended. In the case of an invalid hash (or IOError, which in Python 2 was a subclass of OSError but now is just another name for it), the behavior of just yielding no items may be unintuitive, since on most other errors an exception is raised. However, examining the code reveals this behavior is clearly intentional. Furthrmore, it may be reasonable for applications to rely on it, and it may be convenient in some situations. For backward compatibility, it probably can't be changed significantly. This adds tests that show both an error that does raise an error-representing exception -- a well-formed hash not present in the repository raising ValueError with a suitable message -- and an error that silently causes the iterator to yield zero items.
Configuration menu - View commit details
-
Copy full SHA for 96fc354 - Browse repository at this point
Copy the full SHA 96fc354View commit details -
Expand "invalid hash" test to assert normal StopIteration
Returning an explicit value from a generator function causes that value to be bound to the `value` attribute of the StopIteration exception. This is available as the result of "yield from" when it is used as an expression; or by explicitly catching StopIteration, binding the StopIteration exception to a variable, and accessing the attribute. This feature of generators is rarely used. The `return iter([])` statement in Submodule.iter_items uses this feature, causing the resulting StopIteration exception object to have a `value` attribute that refers to a separate second iterator that also yields no values (gitpython-developers#1779). From context, this behavior is clearly not the goal; a bare return statement should be used here (which has the same effect except for the `value` attribute of the StopIteration exception). The code had used a bare return prior to 82b131c (gitpython-developers#1282), when `return` was changed to `return iter([])`. That was part of a change that added numerous type annotations. It looks like it was either a mistake, or possibly an attempt to work around an old bug in a static type checker. This commit extends the test_iter_items_from_invalid_hash test to assert that the `value` attribute of the StopIteration is its usual default value of None. This commit only extends the test; it does not fix the bug.
Configuration menu - View commit details
-
Copy full SHA for f5dc1c4 - Browse repository at this point
Copy the full SHA f5dc1c4View commit details -
In Submodule.iter_items, don't attach second empty iterator
This fixes the minor bug where a separate empty iterator was bound to the StopIteration exception raised as a result of returning from the generator function (gitpython-developers#1779). This change does not cause what exceptions are raised from GitPython code in any situations, nor how many items any iterators yield.
Configuration menu - View commit details
-
Copy full SHA for c3c008c - Browse repository at this point
Copy the full SHA c3c008cView commit details -
Improve self-documentation of IterableObj and related classes
- Fill in the missing part of the explanation of why to favor iter_items over list_items in IterableObj and Iterable (gitpython-developers#1775). - Move the explanation of how subclasses must treat arguments from the list_items methods to the iter_items methods, because the iter_items methdos are the ones that are abstract and must be overridden by a well-behaved subclass, and also because, since the iter_items methods are preferred for use, they should be the place where less duplicated shared documentation resides. - Subtantially reword the existing documentation for clarity, especially regarding the signifance of extra args and kwargs. - Put the iter_items method before (i.e. above) the list_items method (in each of the IterableObj and Iterable classes), because that method is the one that should be used more often, and because it is also now the one with the more detailed docstring. - Remove and old comment on a return type that said exactly the exact same thing as the annotation. - In Iterable, note deprecation more consistently (and thus in more places). - Rewrite the IterableClassWatcher class docstring to explain exactly what that metaclass achieves.
Configuration menu - View commit details
-
Copy full SHA for dfee31f - Browse repository at this point
Copy the full SHA dfee31fView commit details