Created
June 24, 2024 11:21
-
-
Save mypy-play/bb0277c6f339cbf374a1d2288cb7d5e6 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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