Create a snapshot description of a symbol table node. The representation is nested tuples and dicts. Only externally visible attributes are included.
(node: SymbolNode | None, common: SymbolSnapshot)
| 228 | |
| 229 | |
| 230 | def snapshot_definition(node: SymbolNode | None, common: SymbolSnapshot) -> SymbolSnapshot: |
| 231 | """Create a snapshot description of a symbol table node. |
| 232 | |
| 233 | The representation is nested tuples and dicts. Only externally |
| 234 | visible attributes are included. |
| 235 | """ |
| 236 | if isinstance(node, SYMBOL_FUNCBASE_TYPES): |
| 237 | # TODO: info |
| 238 | if node.type: |
| 239 | signature: tuple[object, ...] = snapshot_type(node.type) |
| 240 | else: |
| 241 | signature = snapshot_untyped_signature(node) |
| 242 | impl: FuncDef | None = None |
| 243 | if isinstance(node, FuncDef): |
| 244 | impl = node |
| 245 | elif node.impl: |
| 246 | impl = node.impl.func if isinstance(node.impl, Decorator) else node.impl |
| 247 | setter_type = None |
| 248 | if isinstance(node, OverloadedFuncDef) and node.items: |
| 249 | first_item = node.items[0] |
| 250 | if isinstance(first_item, Decorator) and first_item.func.is_property: |
| 251 | setter_type = snapshot_optional_type(first_item.var.setter_type) |
| 252 | is_trivial_body = impl.is_trivial_body if impl else False |
| 253 | dataclass_transform_spec = find_dataclass_transform_spec(node) |
| 254 | |
| 255 | deprecated: str | list[str | None] | None = None |
| 256 | if isinstance(node, FuncDef): |
| 257 | deprecated = node.deprecated |
| 258 | elif isinstance(node, OverloadedFuncDef): |
| 259 | deprecated = [node.deprecated] + [ |
| 260 | i.func.deprecated for i in node.items if isinstance(i, Decorator) |
| 261 | ] |
| 262 | |
| 263 | return ( |
| 264 | "Func", |
| 265 | common, |
| 266 | node.is_property, |
| 267 | node.is_final, |
| 268 | node.is_class, |
| 269 | node.is_static, |
| 270 | signature, |
| 271 | is_trivial_body, |
| 272 | dataclass_transform_spec.serialize() if dataclass_transform_spec is not None else None, |
| 273 | deprecated, |
| 274 | setter_type, # multi-part properties are stored as OverloadedFuncDef |
| 275 | ) |
| 276 | elif isinstance(node, Var): |
| 277 | return ("Var", common, snapshot_optional_type(node.type), node.is_final) |
| 278 | elif isinstance(node, Decorator): |
| 279 | # Note that decorated methods are represented by Decorator instances in |
| 280 | # a symbol table since we need to preserve information about the |
| 281 | # decorated function (whether it's a class function, for |
| 282 | # example). Top-level decorated functions, however, are represented by |
| 283 | # the corresponding Var node, since that happens to provide enough |
| 284 | # context. |
| 285 | return ( |
| 286 | "Decorator", |
| 287 | node.is_overload, |
no test coverage detected
searching dependent graphs…