@@ -128,21 +128,15 @@ def _macro_str_replace(text: str) -> str:
128
128
return f"self.template({ text } , locals())"
129
129
130
130
131
- class CaseInsensitiveMapping (dict ):
131
+ class CaseInsensitiveMapping (t . Dict [ str , t . Any ] ):
132
132
def __init__ (self , data : t .Dict [str , t .Any ]) -> None :
133
133
super ().__init__ (data )
134
134
135
- self ._lower = {k .lower (): v for k , v in data .items ()}
136
-
137
135
def __getitem__ (self , key : str ) -> t .Any :
138
- if key in self :
139
- return super ().__getitem__ (key )
140
- return self ._lower [key .lower ()]
136
+ return super ().__getitem__ (key .lower ())
141
137
142
- def get (self , key : str , default : t .Any = None ) -> t .Any :
143
- if key in self :
144
- return super ().get (key , default )
145
- return self ._lower .get (key .lower (), default )
138
+ def get (self , key : str , default : t .Any = None , / ) -> t .Any :
139
+ return super ().get (key .lower (), default )
146
140
147
141
148
142
class MacroDialect (Python ):
@@ -335,7 +329,7 @@ def template(self, text: t.Any, local_variables: t.Dict[str, t.Any]) -> str:
335
329
# We try to convert all variables into sqlglot expressions because they're going to be converted
336
330
# into strings; in sql we don't convert strings because that would result in adding quotes
337
331
base_mapping = {
338
- k : convert_sql (v , self .dialect )
332
+ k . lower () : convert_sql (v , self .dialect )
339
333
for k , v in chain (self .variables .items (), self .locals .items (), local_variables .items ())
340
334
}
341
335
return MacroStrTemplate (str (text )).safe_substitute (CaseInsensitiveMapping (base_mapping ))
0 commit comments