Dump the grammar tables to a pickle file.
(self, filename: Path)
| 98 | self.async_keywords = False |
| 99 | |
| 100 | def dump(self, filename: Path) -> None: |
| 101 | """Dump the grammar tables to a pickle file.""" |
| 102 | |
| 103 | # mypyc generates objects that don't have a __dict__, but they |
| 104 | # do have __getstate__ methods that will return an equivalent |
| 105 | # dictionary |
| 106 | if hasattr(self, "__dict__"): |
| 107 | d = self.__dict__ |
| 108 | else: |
| 109 | d = self.__getstate__() # type: ignore |
| 110 | |
| 111 | with tempfile.NamedTemporaryFile( |
| 112 | dir=os.path.dirname(filename), delete=False |
| 113 | ) as f: |
| 114 | pickle.dump(d, f, pickle.HIGHEST_PROTOCOL) |
| 115 | os.replace(f.name, filename) |
| 116 | |
| 117 | def _update(self, attrs: dict[str, Any]) -> None: |
| 118 | for k, v in attrs.items(): |
no test coverage detected