def METHOD_NAME(self, filename: Path) -> None:
    """Dump the grammar tables to a pickle file."""
    # mypyc generates objects that don't have a __dict__, but they
    # do have __getstate__ methods that will return an equivalent
    # dictionary
    if hasattr(self, "__dict__"):
        d = self.__dict__
    else:
        d = self.__getstate__()  # type: ignore
    with tempfile.NamedTemporaryFile(
        dir=os.path.dirname(filename), delete=False
    ) as f:
        pickle.METHOD_NAME(d, f, pickle.HIGHEST_PROTOCOL)
    os.replace(f.name, filename)