🤡 workaround for path-dependent pyright bug by replicating CanArrayND
#742
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This works around a Pyright bug where it reports false positives if run as e.g.
pyright tests
, instead of justpyright .
. I believe this is the same bug as the one in that from #741.The bug seems to have to do with type parameter defaults: It has to do with generic protocols that have generic type arguments, that sometimes (depending on the order of analysis) falsely reject assignment to it.
This is the case for
optype.nunpy.CanArray
, which has two type parameters with defaults. When runningpyright tests
, Pyright sometimes incorrectly does not allow assigning compatiblenp.ndarray
instances to thisCanArray
protocol. I've only seen this occur in overloads, but I'm not sure if that's relevant here.Either way, I worked around this by replacing the
optype.numpy.CanArray
with a customscipy._typing.CanArray
protocol, that's almost equivelent, apart from its first type parameter not having a default. I.e. it has two type parameters, and only one of them has a default.Note that currently, even without this PR,
pyright .
works fine, and so doespyright scipy-stubs
, andpyright scipy-stubs tests
. But without this workaround,pyright tests
andpyright tests scipy-stubs
will report false positive errors.I'm not sure if I'm going to merge this, as I'm not sure whether the mess this causes is worth it.