Implement __deepcopy__ for Message (#339)
This commit is contained in:
committed by
GitHub
parent
3f377e3bfd
commit
74205e3319
@@ -8,6 +8,7 @@ import sys
|
||||
import typing
|
||||
from abc import ABC
|
||||
from base64 import b64decode, b64encode
|
||||
from copy import deepcopy
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from dateutil.parser import isoparse
|
||||
from typing import (
|
||||
@@ -717,6 +718,14 @@ class Message(ABC):
|
||||
for field_name in self._betterproto.meta_by_field_name
|
||||
)
|
||||
|
||||
def __deepcopy__(self: T, _: Any = {}) -> T:
|
||||
kwargs = {}
|
||||
for name in self._betterproto.sorted_field_names:
|
||||
value = self.__raw_get(name)
|
||||
if value is not PLACEHOLDER:
|
||||
kwargs[name] = deepcopy(value)
|
||||
return self.__class__(**kwargs) # type: ignore
|
||||
|
||||
@property
|
||||
def _betterproto(self) -> ProtoClassMetadata:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user