@@ -160,16 +160,22 @@ def make_python_env(
160
160
def _extract_macro_func_variable_references (macro_func : exp .Expression ) -> t .Set [str ]:
161
161
references = set ()
162
162
163
- for n in macro_func .walk ():
164
- if n is macro_func :
165
- continue
163
+ # Don't descend into nested MacroFunc nodes besides @VAR() and @BLUEPRINT_VAR(), because
164
+ # they will be handled in a separate call of _extract_macro_func_variable_references.
165
+ def _prune_nested_macro_func (expression : exp .Expression ) -> bool :
166
+ return (
167
+ type (n ) is d .MacroFunc
168
+ and n is not macro_func
169
+ and n .this .name .lower () not in (c .VAR , c .BLUEPRINT_VAR )
170
+ )
166
171
167
- # Don't descend into nested MacroFunc nodes besides @VAR() and @BLUEPRINT_VAR(), because
168
- # they will be handled in a separate call of _extract_macro_func_variable_references.
169
- if isinstance (n , d .MacroFunc ):
172
+ for n in macro_func .walk (prune = _prune_nested_macro_func ):
173
+ if type (n ) is d .MacroFunc :
170
174
this = n .this
171
- if this .name .lower () in (c .VAR , c .BLUEPRINT_VAR ) and this .expressions :
172
- references .add (this .expressions [0 ].this .lower ())
175
+ args = this .expressions
176
+
177
+ if this .name .lower () in (c .VAR , c .BLUEPRINT_VAR ) and args and args [0 ].is_string :
178
+ references .add (args [0 ].this .lower ())
173
179
elif isinstance (n , d .MacroVar ):
174
180
references .add (n .name .lower ())
175
181
elif isinstance (n , (exp .Identifier , d .MacroStrReplace , d .MacroSQL )) and "@" in n .name :
0 commit comments