| 49 | |
| 50 | |
| 51 | class Code: |
| 52 | def __init__(self, **kwds: Any): |
| 53 | self.__dict__.update(kwds) |
| 54 | |
| 55 | def __repr__(self) -> str: |
| 56 | return f"Code(**{self.__dict__})" |
| 57 | |
| 58 | co_localsplusnames: Tuple[str] |
| 59 | co_localspluskinds: Tuple[int] |
| 60 | |
| 61 | def get_localsplus_names(self, select_kind: int) -> Tuple[str, ...]: |
| 62 | varnames: list[str] = [] |
| 63 | for name, kind in zip(self.co_localsplusnames, |
| 64 | self.co_localspluskinds): |
| 65 | if kind & select_kind: |
| 66 | varnames.append(name) |
| 67 | return tuple(varnames) |
| 68 | |
| 69 | @property |
| 70 | def co_varnames(self) -> Tuple[str, ...]: |
| 71 | return self.get_localsplus_names(CO_FAST_LOCAL) |
| 72 | |
| 73 | @property |
| 74 | def co_cellvars(self) -> Tuple[str, ...]: |
| 75 | return self.get_localsplus_names(CO_FAST_CELL) |
| 76 | |
| 77 | @property |
| 78 | def co_freevars(self) -> Tuple[str, ...]: |
| 79 | return self.get_localsplus_names(CO_FAST_FREE) |
| 80 | |
| 81 | @property |
| 82 | def co_nlocals(self) -> int: |
| 83 | return len(self.co_varnames) |
| 84 | |
| 85 | |
| 86 | class Reader: |