Make Message.__getattribute__ invisible to type checkers (#359)
This lets linters know that we shouldn't access fields that aren't actually defined
This commit is contained in:
parent
402c21256f
commit
b9b0b22d57
@ -18,6 +18,7 @@ from datetime import (
|
|||||||
timezone,
|
timezone,
|
||||||
)
|
)
|
||||||
from typing import (
|
from typing import (
|
||||||
|
TYPE_CHECKING,
|
||||||
Any,
|
Any,
|
||||||
Callable,
|
Callable,
|
||||||
Dict,
|
Dict,
|
||||||
@ -693,18 +694,20 @@ class Message(ABC):
|
|||||||
]
|
]
|
||||||
return f"{self.__class__.__name__}({', '.join(parts)})"
|
return f"{self.__class__.__name__}({', '.join(parts)})"
|
||||||
|
|
||||||
def __getattribute__(self, name: str) -> Any:
|
if not TYPE_CHECKING:
|
||||||
"""
|
|
||||||
Lazily initialize default values to avoid infinite recursion for recursive
|
|
||||||
message types
|
|
||||||
"""
|
|
||||||
value = super().__getattribute__(name)
|
|
||||||
if value is not PLACEHOLDER:
|
|
||||||
return value
|
|
||||||
|
|
||||||
value = self._get_field_default(name)
|
def __getattribute__(self, name: str) -> Any:
|
||||||
super().__setattr__(name, value)
|
"""
|
||||||
return value
|
Lazily initialize default values to avoid infinite recursion for recursive
|
||||||
|
message types
|
||||||
|
"""
|
||||||
|
value = super().__getattribute__(name)
|
||||||
|
if value is not PLACEHOLDER:
|
||||||
|
return value
|
||||||
|
|
||||||
|
value = self._get_field_default(name)
|
||||||
|
super().__setattr__(name, value)
|
||||||
|
return value
|
||||||
|
|
||||||
def __setattr__(self, attr: str, value: Any) -> None:
|
def __setattr__(self, attr: str, value: Any) -> None:
|
||||||
if attr != "_serialized_on_wire":
|
if attr != "_serialized_on_wire":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user