Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created June 24, 2024 11:21
Show Gist options
  • Save mypy-play/bb0277c6f339cbf374a1d2288cb7d5e6 to your computer and use it in GitHub Desktop.
Save mypy-play/bb0277c6f339cbf374a1d2288cb7d5e6 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
from typing import Any, cast
from enum import Enum
class Message:
class Direction(Enum):
IN = "IN"
OUT = "OUT"
class MetaProtoWrapper(type):
def __getattribute__(cls, name: str):
try:
return super().__getattribute__(name)
except AttributeError:
return getattr(cls.Meta.protocol_buffer_type, name)
class ProtoWrapper(metaclass=MetaProtoWrapper):
class Meta:
protocol_buffer_type = Message
direction_in: ProtoWrapper.Direction = ProtoWrapper.Direction.IN # Name "ProtoWrapper.Direction" is not defined [name-defined]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment