HPInc / HP-Digital-Microfluidics

HP Digital Microfluidics Software Platform and Libraries
MIT License
2 stars 0 forks source link

Spurious MyPy error on Delayed/Postable variance mismatch #216

Closed EvanKirshenbaum closed 5 months ago

EvanKirshenbaum commented 5 months ago

The MyPy scans on push for Python 3.10 (but not 3.9) are now giving me an error on the declaration of Postable:

class Postable(Delayed[Tcontra]):

The error is

mpam/src/mpam/types.py:1862:1: error: Variance of TypeVar "Tcontra" incompatible with variance in parent type  [type-var]

The problem is that Postable is generic in a contravariant type, while Delayed is generic in a covariant type:

class Delayed(Generic[Tco]):

This is correct and not a problem, but I'm going to have to figure out how to get MyPy not to complain about it. (Or, I guess, learn why it is, in fact, not a safe thing to do.)

Migrated from internal repository. Originally created by @EvanKirshenbaum on Jan 07, 2023 at 2:16 PM PST. Closed on Jan 07, 2023 at 2:24 PM PST.
EvanKirshenbaum commented 5 months ago

This issue was referenced by the following commit before migration:

EvanKirshenbaum commented 5 months ago

I just added

# type: ignore [type-var]

and that got rid of the warning. I should look at some point to see if they have a point, but I'm nearly certain it's safe.

Migrated from internal repository. Originally created by @EvanKirshenbaum on Jan 07, 2023 at 2:24 PM PST.