You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 its
override IndexFile._process_diff_args. Further changes related to
this remain necessary, and at this time, this adds one mypy error.
The _process_diff_args methods did not handle Diffable.Index. The
base class method would pass it through, but it would not be usable
when then passed to "git diff". Instead, it is handled with correct
behavior at runtime in Diffable.diff and its IndexFile.diff
override, which handle it themselves and ensure it is never passed
to 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 those
methods have never actually worked with it and it probably wouldn't
make sense for them to handle it. However, this does also attempt
to help mypy figure out that Diffable.Index cannot end up as an
element of its local variable `args`. This attempt is unsuccessful.
The problem with the `args` local variable may be the reason
including Index in the parameter type annotations appeared correct
or necessary before. The issue is that Diffable.Index, even though
it ought to be used as an opaque constant, is a class. Its static
type is Type[Diffable.Index], but mypy is unable to infer that
there are no other objects of that static type, because if
Diffable.Index were subclassed, and the type object produced from
doing 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 decorate
the Diffable.Index class as `@final`. This works for pyright (and
thus 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 constant
rather than a class, so it can be annotated as a literal.
0 commit comments