Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork941
Commit0e1df29
committed
Start fixing diff and _process_diff_args type annotations
This fixes three mypy errors by modifying the Diffable.diff,Diffable._process_diff_args, and its IndexFile._process_diff_argsoverride. This change, so far, adds no suppressions, and evenremoves some preexisting suppressions that were ineffective becauseof how they were written (not being on the first line of the def).However, this is not a complete fix of those annotationsthemselves. This is because although the `other` parameter toDiffable.diff and Diffable._process_diff_args does not appearintended to have been as broad as including object in the union hadthe effect of making it -- any union with object as an alternativeis equivalent to object itself -- it should nonetheless be broaderthan the changes here make it.Once that is fixed, it may not be possible to maintain compliancewith the Liskov substitution principle, in which case a suppression,corresponding to one of those that was removed but fixed so it hasan effect, may need to be introduced, since actually fixing the LSPviolation would be a breaking change.Specifically, as seen in797e962 and09053c5 in#1285, the objectalternative was originally intended not to indicate that any objectis allowed, but instead to allow the NULL_TREE constant, which was(and currently remains) implemented as a direct instance of object.The type of NULL_TREE is not the core problem. It can be fixed toallow a narrowly scoped annotation. One way is by making NULL_TREEan enumeration constant and annotating `Literal[NULL_TREE]`.Rather, the problem is that the IndexFile.diff override really doesnot accept NULL_TREE. It may not be feasible to modify it to acceptit. Even if that is to be done, it should be for runtimecorrectness, and likely have a test case added for it, and may notbe suitable for inclusion alongside these static typing fixes.So when the base class method's annotation is broadened to add sucha literal or equivalent, the override's annotation in the derivedclass may not reasonably be able to change accordingly, as LSPwould dictate.Part of the change here adds a missing os.PathLike[str] alternativeto _process_diff_args. For now I've opted to include both str(already present) and os.PathLike[str] separately, rather thanconsolidating them into PathLike (in GitPython, PathLike isgit.types.PathLike, which is Union[str, os.PathLike[str]]). Thereason is that, while some str arguments may be paths, others maybe options.However, that stylistic choice may not be justified, since it is atodds with some existing uses of PathLike in GitPython to cover bothstr as a path and str as a non-path, including in theimplementation of Diffable.diff itself. So those may beconsolidated in a forthcoming commit.1 parented6ead9 commit0e1df29
2 files changed
+11
-9
lines changedLines changed: 7 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3 | 3 |
| |
4 | 4 |
| |
5 | 5 |
| |
| 6 | + | |
6 | 7 |
| |
7 | 8 |
| |
8 | 9 |
| |
| |||
98 | 99 |
| |
99 | 100 |
| |
100 | 101 |
| |
101 |
| - | |
102 |
| - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
103 | 105 |
| |
104 | 106 |
| |
105 | 107 |
| |
| |||
110 | 112 |
| |
111 | 113 |
| |
112 | 114 |
| |
113 |
| - | |
| 115 | + | |
114 | 116 |
| |
115 | 117 |
| |
116 | 118 |
| |
| |||
159 | 161 |
| |
160 | 162 |
| |
161 | 163 |
| |
162 |
| - | |
| 164 | + | |
163 | 165 |
| |
164 | 166 |
| |
165 | 167 |
| |
| |||
195 | 197 |
| |
196 | 198 |
| |
197 | 199 |
| |
198 |
| - | |
| 200 | + | |
199 | 201 |
| |
200 | 202 |
| |
201 | 203 |
| |
|
Lines changed: 4 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
644 | 644 |
| |
645 | 645 |
| |
646 | 646 |
| |
647 |
| - | |
648 |
| - | |
649 |
| - | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
650 | 650 |
| |
651 | 651 |
| |
652 | 652 |
| |
| |||
1478 | 1478 |
| |
1479 | 1479 |
| |
1480 | 1480 |
| |
1481 |
| - | |
| 1481 | + | |
1482 | 1482 |
| |
1483 | 1483 |
| |
1484 | 1484 |
| |
|
0 commit comments
Comments
(0)