Get the concrete value of the enumerated value with that name. The name of the enumerated value must be a string. If there is no value with that name in the enumeration, a KeyError is raised. Examples -------- Let ``enum`` be an enumerated type defined as:
(self, name: str)
| 158 | self.__dict__[name] = value |
| 159 | |
| 160 | def __getitem__(self, name: str) -> Any: |
| 161 | """Get the concrete value of the enumerated value with that name. |
| 162 | |
| 163 | The name of the enumerated value must be a string. If there is no value |
| 164 | with that name in the enumeration, a KeyError is raised. |
| 165 | |
| 166 | Examples |
| 167 | -------- |
| 168 | Let ``enum`` be an enumerated type defined as: |
| 169 | |
| 170 | >>> enum = Enum({'T0': 0, 'T1': 2, 'T2': 5}) |
| 171 | |
| 172 | then: |
| 173 | |
| 174 | >>> enum['T1'] |
| 175 | 2 |
| 176 | >>> enum['foo'] |
| 177 | Traceback (most recent call last): |
| 178 | ... |
| 179 | KeyError: "no enumerated value with that name: 'foo'" |
| 180 | |
| 181 | """ |
| 182 | try: |
| 183 | return self._names[name] |
| 184 | except KeyError: |
| 185 | raise KeyError(f"no enumerated value with that name: {name!r}") |
| 186 | |
| 187 | def __setitem__(self, name: Any, value: Any) -> NoReturn: |
| 188 | """Forbidden operation.""" |
no outgoing calls