-
According to internals docs, In the following example, how does pyright infer the type of test1.py import test2
var: str = test2.a test2.py def f():
return 1 + 2
a = f()
b: str = 'xyz' ❯ pyright test1.py
test1.py
test1.py:3:12 - error: Expression of type "int" cannot be assigned to declared type "str"
"int" is incompatible with "str" (reportGeneralTypeIssues)
1 error, 0 warnings, 0 infos
Completed in 0.527sec It's not even a direct assignment. This means that pyright infers the return type of |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Are you asking simply because you're curious? Or do you see a problem here? The binder doesn't do any type evaluation. It simply discovers symbols and associates them with scopes. It also builds the code flow graph that is used later during type evaluation. The typeEvaluator is the component that determines the type of a symbol or an expression. It does this on demand, and it can do it in any order. It's smart enough to evaluate dependent symbol types even if that requires jumping around between files. The checker simply visits every statement in a file and invokes the type evaluator on every statement. In the example above, pyright is asked to analyze only one file: Then the checker starts to visit each statement in Hopefully that gives you a sense for how the various components work. Let me know if any of that was unclear. |
Beta Was this translation helpful? Give feedback.
Are you asking simply because you're curious? Or do you see a problem here?
The binder doesn't do any type evaluation. It simply discovers symbols and associates them with scopes. It also builds the code flow graph that is used later during type evaluation.
The typeEvaluator is the component that determines the type of a symbol or an expression. It does this on demand, and it can do it in any order. It's smart enough to evaluate dependent symbol types even if that requires jumping around between files.
The checker simply visits every statement in a file and invokes the type evaluator on every statement.
In the example above, pyright is asked to analyze only one file:
test1.py
. That means …