Replies: 2 comments
-
It would be a pretty significant modification to support this, as it breaks some fundamental assumptions in pyright's design. If a symbol has a declared type (as |
Beta Was this translation helpful? Give feedback.
-
@erictraut Thank you for responding! Do you have any ideas on how to determine the value of a local variable? Any concepts, tools, or thoughts are welcome. Currently, I am considering constructing a tree recursively based on the declaration of the local variable. The parameter node will serve as a placeholder on the tree, and input the actual argument during function invocation to the corresponding placeholder. Finally, I would execute the tree to get the value of the local variable. However, I am not sure if this is the best way to solve this problem. |
Beta Was this translation helpful? Give feedback.
-
I am seeking assistance on integrating a particular feature into a development tool that leverages Pyright as its static analysis engine.
My objective is to evaluate local variables within a function based on the arguments passed to that function during static analysis.
To leverage Pyright’s type inference capabilities, I hope to add an assignment statement for a variable directly in the AST of a function body. This would effectively define the function's parameters as local variables within that function, allowing Pyright to infer the types of subsequent local variable usages, and by extension, deduce their literal values when called.
Consider the following Python code as an example:
My goal is to dynamically insert assignments, such as
arg = "hello"
orarg = "world"
, into thefoo
function body for each invocation offoo
. Following this insertion, I expect Pyright to infer the type ofprocessed
as either "arg-hello" or "arg-world", based on the modified AST. This, in turn, should enable Pyright to deduce that the argument passed tobar
during these calls is of type "arg-hello" or "arg-world".Is there a method to programmatically add a statement node to the AST used by Pyright, and subsequently refresh or re-analyze the AST to update the type information for variables within the AST accordingly?
Beta Was this translation helpful? Give feedback.
All reactions