Resolve a variable name in a possibly local context. Parameters ---------- key : str A variable name is_local : bool Flag indicating whether the variable is local or not (prefixed with the '@' symbol) Returns
(self, key: str, is_local: bool)
| 206 | return bool(len(self.resolvers)) |
| 207 | |
| 208 | def resolve(self, key: str, is_local: bool): |
| 209 | """ |
| 210 | Resolve a variable name in a possibly local context. |
| 211 | |
| 212 | Parameters |
| 213 | ---------- |
| 214 | key : str |
| 215 | A variable name |
| 216 | is_local : bool |
| 217 | Flag indicating whether the variable is local or not (prefixed with |
| 218 | the '@' symbol) |
| 219 | |
| 220 | Returns |
| 221 | ------- |
| 222 | value : object |
| 223 | The value of a particular variable |
| 224 | """ |
| 225 | try: |
| 226 | # only look for locals in outer scope |
| 227 | if is_local: |
| 228 | return self.scope[key] |
| 229 | |
| 230 | # not a local variable so check in resolvers if we have them |
| 231 | if self.has_resolvers: |
| 232 | return self.resolvers[key] |
| 233 | |
| 234 | # if we're here that means that we have no locals and we also have |
| 235 | # no resolvers |
| 236 | assert not is_local and not self.has_resolvers |
| 237 | return self.scope[key] |
| 238 | except KeyError: |
| 239 | try: |
| 240 | # last ditch effort we look in temporaries |
| 241 | # these are created when parsing indexing expressions |
| 242 | # e.g., df[df > 0] |
| 243 | return self.temps[key] |
| 244 | except KeyError as err: |
| 245 | raise UndefinedVariableError(key, is_local) from err |
| 246 | |
| 247 | def swapkey(self, old_key: str, new_key: str, new_value=None) -> None: |
| 248 | """ |