-
-
Notifications
You must be signed in to change notification settings - Fork 905
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
Git.version_info type annotation is overly specific in length #1830
Comments
Indeed, having more than Thus this can probably be reduced to 3 digits to be more realistic. Also a question is if that would be a breaking change. |
Some downstream versions have a fourth numeric part with no intervening non-numeric parts. This fourth part identifies the downstream version number, to reflect that the downstream version may have its own patches and also that there may be more than one downstream version per upstream (major, minor, patch) version, such as to backport security fixes from later versions. In particular, the system
That produces a If it is always three or four parts, then the type could be given as An argument for using For the annotation change itself, that may be breaking in the weak sense that type checkers would start flagging new type errors. But these would be type errors that were already present. So I think that would be justified as a bugfix. Another option is to go in the opposite direction from (There is also the question of whether the build number |
Thanks for the clarification. I see what I misunderstood - this issue wasn't about truncating the amount of digits, but to adjust the type annotation to better represent the reality of sometimes only having three digits anyway.
It would certainly be nice to have named fields for each positional field as well - type-checkers probably will do a better job at explaining the data contained within to the user.
I'd prefer to treat this as out-of-scope for this issue, without the immediate need to take on such a change, despite it's potential usefulness. |
I am thinking maybe that this test should be narrowed to assert whatever we assume is always true of a real Lines 173 to 174 in afa5754
Then the appropriate named tuple type or types can be made--or, alternatively, it can be discovered that this cannot reasonably be done--and the best type annotation can be figured out. Right now it uses the regular expression:
It makes sense that this is so general, since the goal seems to be just to verify that Yet, I do worry about breaking things if people are using weird Lines 379 to 384 in afa5754
I'm not sure if it's really okay to change that to check something more specific. If not, then I'm not sure how specific the return type of One possibility is to make a variable-length named tuple type that raises the usual I had originally thought this bug should be fixed together with #1829, but I'm realizing that, even with these decisions to be made here, this is probably faster and easier to fix and test and could reasonably be done on its own. |
I definitely don't have an answer, but would hope that the new way of doing things won't be more restrictive than the old. |
This actually narrows things down quite a bit, because there are only a few ways I know how to do it that avoid being more restrictive than before. The existing restrictionOne already-present restriction is that the output of Lines 817 to 818 in afa5754
If there are fewer than three space-separated fields in the output of Should this be a union?We do not enforce that the output begins with Union[Tuple[int], Tuple[int, int], Tuple[int, int, int], Tuple[int, int, int, int]] There is no syntactic reason to shy away from allowing tuples of zero Union[Tuple[()], Tuple[int], Tuple[int, int], Tuple[int, int, int], Tuple[int, int, int, int]] But the restriction that there are at most four fields seems less important for using the library than knowledge that there are at least some number of fields. As such, expressing this as a union of tuple of types seems like it is not justified if
In addition, writing code that returns such a union is cumbersome to do in a way that is fully checkable (i.e., without a So I think this points toward expressing the type as being a tuple whose length is not statically attested but whose elements are all known to be of type Tuple[int, ...] Why not make it like
|
This broadens the type annoation on the Git.version_info property, for gitpython-developers#1830. It also revises the docstring for clarity, and continues refactoring and comment changes (also for clarity).
Thanks so much for this incredible summary of the whole ordeal, I feel like I can picture the situation much more clearly now. Please go ahead like you prefer and we take it from there. In case it helps, it's also possible to internally use a new version of this field, |
I have actually already done so, in that the approach in "A simple, first solution" is included in #1838, along with fixes for the other known |
The
version_info
property is declared to be a length-4 tuple:GitPython/git/cmd.py
Lines 833 to 841 in afa5754
But it often has fewer values, which is intentional:
GitPython/git/cmd.py
Lines 814 to 826 in afa5754
So the type annotation should be changed, but I am unsure what it should be changed to, whether any additional documentation should be added, and whether having fewer than some number of numeric fields should be treated as an error and cause an exception to be raised.
If the type annotation should reflect that only a few specific lengths are reasonable, then it could be expressed as a
Union
of specific-lengthTuple
types. Otherwise it could be expressed as a variable-length tuple by writing the type asTuple[int, ...]
.I recommend this be solved in such a way that the
cast
can be removed. Currently, thecast
is working around ambiguity in how the return type is intended to be understood.This is separate from #1829, though I noticed it while looking into that and they could possibly be fixed (or improved or otherwise closed) together.
The text was updated successfully, but these errors were encountered: