pyright 1.1.401
Consider the snippet below - it seems bidirectional inference doesn't work when assigning symbols from other module.
In theory in the example below xxx.callback = lambda x: x.bit_count() should work out similar to callback = lambda x: x.bit_count() - by bydirectional inference, the type of lambda x: x.bit_count() is recognized as type of xxx.callback (Callable[[int], int]), x type to be recognized as int automatically and xxx.callback should keep it's original type after the assignment.
Same for xxx.lst = [].
xxx.py
from typing import Callable
callback: Callable[[int], int] = lambda x: x.bit_count()
lst: list[int] = []
Main script:
from typing import Callable
import xxx
class A:
a: Callable[[int], int]
@staticmethod
def test(a: Callable[[int], int]): ...
callback: Callable[[int], int] = lambda x: x.bit_count()
# OK
A.test(lambda x: x.bit_count())
# OK
A.a = lambda x: x.bit_count()
# OK
callback = lambda x: x.bit_count()
# Bydirectional inference doesn't work.
# Type of "xxx.callback" is "(int) -> int"
reveal_type(xxx.callback)
xxx.callback = lambda x: x.bit_count()
# Type of "xxx.callback" is "(x: Unknown) -> Unknown"
reveal_type(xxx.callback)
# Type of "xxx.lst" is "list[int]"
reveal_type(xxx.lst)
xxx.lst = []
# Type of "xxx.lst" is "list[Unknown]"
reveal_type(xxx.lst)
Update: confirm issue as resolved.
pyright 1.1.401
Consider the snippet below - it seems bidirectional inference doesn't work when assigning symbols from other module.
In theory in the example below
xxx.callback = lambda x: x.bit_count()should work out similar tocallback = lambda x: x.bit_count()- by bydirectional inference, the type oflambda x: x.bit_count()is recognized as type ofxxx.callback(Callable[[int], int]),xtype to be recognized asintautomatically andxxx.callbackshould keep it's original type after the assignment.Same for
xxx.lst = [].xxx.py
Main script:
Update: confirm issue as resolved.