summaryrefslogtreecommitdiffstats
path: root/tests/roots/test-ext-autodoc/target/enums.py
blob: 6b2731672d245c1a629818a2d00040527840f554 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# ruff: NoQA: D403, PIE796
import enum
from typing import final


class MemberType:
    """Custom data type with a simple API."""

    # this mangled attribute will never be shown on subclasses
    # even if :inherited-members: and :private-members: are set
    __slots__ = ('__data',)

    def __new__(cls, value):
        self = object.__new__(cls)
        self.__data = value
        return self

    def __str__(self):
        """inherited"""
        return self.__data

    def __repr__(self):
        return repr(self.__data)

    def __reduce__(self):
        # data types must be pickable, otherwise enum classes using this data
        # type will be forced to be non-pickable and have their __module__ set
        # to '<unknown>' instead of, for instance, '__main__'
        return self.__class__, (self.__data,)

    @final
    @property
    def dtype(self):
        """docstring"""
        return 'str'

    def isupper(self):
        """inherited"""
        return self.__data.isupper()


class EnumCls(enum.Enum):
    """this is enum class"""

    #: doc for val1
    val1 = 12
    val2 = 23  #: doc for val2
    val3 = 34
    """doc for val3"""
    val4 = 34

    def say_hello(self):
        """a method says hello to you."""

    @classmethod
    def say_goodbye(cls):
        """a classmethod says good-bye to you."""


class EnumClassWithDataType(MemberType, enum.Enum):
    """this is enum class"""

    x = 'x'

    def say_hello(self):
        """docstring"""

    @classmethod
    def say_goodbye(cls):
        """docstring"""


class ToUpperCase:  # not inheriting from enum.Enum
    @property
    def value(self):  # bypass enum.Enum.value
        """uppercased"""
        return str(self._value_).upper()  # type: ignore[attr-defined]


class Greeter:
    def say_hello(self):
        """inherited"""

    @classmethod
    def say_goodbye(cls):
        """inherited"""


class EnumClassWithMixinType(ToUpperCase, enum.Enum):
    """this is enum class"""

    x = 'x'

    def say_hello(self):
        """docstring"""

    @classmethod
    def say_goodbye(cls):
        """docstring"""


class EnumClassWithMixinTypeInherit(Greeter, ToUpperCase, enum.Enum):
    """this is enum class"""

    x = 'x'


class Overridden(enum.Enum):
    def override(self):
        """inherited"""
        return 1


class EnumClassWithMixinEnumType(Greeter, Overridden, enum.Enum):
    """this is enum class"""

    x = 'x'

    def override(self):
        """overridden"""
        return 2


class EnumClassWithMixinAndDataType(Greeter, ToUpperCase, MemberType, enum.Enum):
    """this is enum class"""

    x = 'x'

    def say_hello(self):
        """overridden"""

    @classmethod
    def say_goodbye(cls):
        """overridden"""

    def isupper(self):
        """overridden"""
        return False

    def __str__(self):
        """overridden"""
        return super().__str__()


class _ParentEnum(Greeter, Overridden, enum.Enum):
    """docstring"""


class EnumClassWithParentEnum(ToUpperCase, MemberType, _ParentEnum, enum.Enum):
    """this is enum class"""

    x = 'x'

    def isupper(self):
        """overridden"""
        return False

    def __str__(self):
        """overridden"""
        return super().__str__()


class _SunderMissingInNonEnumMixin:
    @classmethod
    def _missing_(cls, value):
        """inherited"""
        return super()._missing_(value)  # type: ignore[misc]


class _SunderMissingInEnumMixin(enum.Enum):
    @classmethod
    def _missing_(cls, value):
        """inherited"""
        return super()._missing_(value)


class _SunderMissingInDataType(MemberType):
    @classmethod
    def _missing_(cls, value):
        """inherited"""
        return super()._missing_(value)  # type: ignore[misc]


class EnumSunderMissingInNonEnumMixin(_SunderMissingInNonEnumMixin, enum.Enum):
    """this is enum class"""


class EnumSunderMissingInEnumMixin(_SunderMissingInEnumMixin, enum.Enum):
    """this is enum class"""


class EnumSunderMissingInDataType(_SunderMissingInDataType, enum.Enum):
    """this is enum class"""


class EnumSunderMissingInClass(enum.Enum):
    """this is enum class"""

    @classmethod
    def _missing_(cls, value):
        """docstring"""
        return super()._missing_(value)


class _NamePropertyInNonEnumMixin:
    @property
    def name(self):
        """inherited"""
        return super().name  # type: ignore[misc]


class _NamePropertyInEnumMixin(enum.Enum):
    @property
    def name(self):
        """inherited"""
        return super().name


class _NamePropertyInDataType(MemberType):
    @property
    def name(self):
        """inherited"""
        return super().name  # type: ignore[misc]


class EnumNamePropertyInNonEnumMixin(_NamePropertyInNonEnumMixin, enum.Enum):
    """this is enum class"""


class EnumNamePropertyInEnumMixin(_NamePropertyInEnumMixin, enum.Enum):
    """this is enum class"""


class EnumNamePropertyInDataType(_NamePropertyInDataType, enum.Enum):
    """this is enum class"""


class EnumNamePropertyInClass(enum.Enum):
    """this is enum class"""

    @property
    def name(self):
        """docstring"""
        return super().name