Closed hmc-cs-mdrissi closed 1 year ago
This issue is related to this one. It has to do your use of a union (Union[Tensor, SparseTensor]
) in a value expression. Unions should generally be used only within type expressions. They are officially supported in a few special cases such as TypeVar bounds, constraints, and arguments passed to isinstance
or issubclass
. You're using it in other places where they are not supported by a strict reading of PEP 484.
As we discussed in the context of the other bug report, the type system doesn't currently support TypeForm
, so I'm inclined to support your rather unorthodox use here. I've made a change that fixes this issue. It will be included in the next release.
This is addressed in pyright 1.1.306, which I just published. It will also be included in a future release of pylance.
Describe the bug I'm unsure on exact issue. I know overload/lambda are key but still unsure what's special about this example vs similar ones I have. I've been able to minimize it down to ~60 line program and have stubbed out implementation.
One small variation that passes type checking is to simplify as_string definition to,
By removing overloaded definition it passes. To Reproduce Run pyright 1.1.305. Produces false positive error on last line of,
Except as_string has one overload that does accept a Tensor as input.
Expected behavior No error. This code passed type checking on 1.1.303. It started failing on 1.1.304. In particular as_string function has two overloads but if you delete second overload and make it no longer overloaded it passes type checking. I wouldn't expect adding an overload to cause it to not be able to match first function anymore.
For lambda it's related to bidirectional inference. If I remove : FeatureRef and make it just ` = lambda x: as_string(densify(x.get(dropoff_census_tract, Union[Tensor, SparseTensor])))` the error disappears. In real usage the bidirectional inference happens because I pass lambda to another function that is annotated for it's arguments.
edit: I have a second somewhat similar example that I'm thinking is same bug. This re-uses some of definitions from first example. Similar to first example it passes type checking <=1.1.303 and fails to check >1.1.304.