-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
addressed in next versionIssue is fixed and will appear in next published versionIssue is fixed and will appear in next published versionbugSomething isn't workingSomething isn't working
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
addressed in next versionIssue is fixed and will appear in next published versionIssue is fixed and will appear in next published versionbugSomething isn't workingSomething isn't working