Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork944
Commit2f5e258
committed
Annotate _process_diff_args without Diffable.Index
This removes the static type of Diffable's nested Index class,Type["Index"], from the Diffable._process_diff_args method, and itsoverride IndexFile._process_diff_args. Further changes related tothis remain necessary, and at this time, this adds one mypy error.The _process_diff_args methods did not handle Diffable.Index. Thebase class method would pass it through, but it would not be usablewhen then passed to "git diff". Instead, it is handled with correctbehavior at runtime in Diffable.diff and its IndexFile.diffoverride, which handle it themselves and ensure it is never passedto any _process_diff_args implementation.That was already the case. The change here is mostly to type hints,removing it from the _process_diff_args annotations, since thosemethods have never actually worked with it and it probably wouldn'tmake sense for them to handle it. However, this does also attemptto help mypy figure out that Diffable.Index cannot end up as anelement of its local variable `args`. This attempt is unsuccessful.The problem with the `args` local variable may be the reasonincluding Index in the parameter type annotations appeared corrector necessary before. The issue is that Diffable.Index, even thoughit ought to be used as an opaque constant, is a class. Its statictype is Type[Diffable.Index], but mypy is unable to infer thatthere are no other objects of that static type, because ifDiffable.Index were subclassed, and the type object produced fromdoing so (i.e. the subclass itself) were passed as an `other`argument to the diff method, then the `other is Diffable.Index`condition would evaluate to False.Therefore to solve this problem it should be sufficient to decoratethe Diffable.Index class as `@final`. This works for pyright (andthus also pylance), but it does not work for mypy (even in 1.9.0).So that still has to be solved, and (other than via suppressions)it may be necessary to make Diffable.Index an enumeration constantrather than a class, so it can be annotated as a literal.1 parent7204cc1 commit2f5e258
3 files changed
+10
-8
lines changedLines changed: 6 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
28 | 28 |
| |
29 | 29 |
| |
30 | 30 |
| |
31 |
| - | |
| 31 | + | |
32 | 32 |
| |
33 | 33 |
| |
34 | 34 |
| |
| |||
94 | 94 |
| |
95 | 95 |
| |
96 | 96 |
| |
| 97 | + | |
97 | 98 |
| |
98 | 99 |
| |
99 | 100 |
| |
100 | 101 |
| |
101 | 102 |
| |
102 |
| - | |
103 |
| - | |
| 103 | + | |
| 104 | + | |
104 | 105 |
| |
105 | 106 |
| |
106 | 107 |
| |
| |||
161 | 162 |
| |
162 | 163 |
| |
163 | 164 |
| |
164 |
| - | |
| 165 | + | |
165 | 166 |
| |
166 | 167 |
| |
167 | 168 |
| |
| |||
184 | 185 |
| |
185 | 186 |
| |
186 | 187 |
| |
187 |
| - | |
| 188 | + | |
188 | 189 |
| |
189 | 190 |
| |
190 | 191 |
| |
|
Lines changed: 2 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
645 | 645 |
| |
646 | 646 |
| |
647 | 647 |
| |
648 |
| - | |
649 |
| - | |
| 648 | + | |
| 649 | + | |
650 | 650 |
| |
651 | 651 |
| |
652 | 652 |
| |
| |||
1494 | 1494 |
| |
1495 | 1495 |
| |
1496 | 1496 |
| |
1497 |
| - | |
1498 | 1497 |
| |
1499 | 1498 |
| |
1500 | 1499 |
| |
|
Lines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
22 | 22 |
| |
23 | 23 |
| |
24 | 24 |
| |
| 25 | + | |
25 | 26 |
| |
26 | 27 |
| |
27 | 28 |
| |
| |||
30 | 31 |
| |
31 | 32 |
| |
32 | 33 |
| |
| 34 | + | |
33 | 35 |
| |
34 | 36 |
| |
35 | 37 |
| |
|
0 commit comments
Comments
(0)