MCPcopy
hub / github.com/danielgtaylor/python-betterproto / try_value

Method try_value

src/betterproto/enum.py:166–183  ·  view source on GitHub ↗

Return the value which corresponds to the value. Parameters ----------- value: :class:`int` The value of the enum member to get. Returns ------- :class:`Enum` The corresponding member or a new instance of the enum if

(cls, value: int = 0)

Source from the content-addressed store, hash-verified

164
165 @classmethod
166 def try_value(cls, value: int = 0) -> Self:
167 """Return the value which corresponds to the value.
168
169 Parameters
170 -----------
171 value: :class:`int`
172 The value of the enum member to get.
173
174 Returns
175 -------
176 :class:`Enum`
177 The corresponding member or a new instance of the enum if
178 ``value`` isn't actually a member.
179 """
180 try:
181 return cls._value_map_[value]
182 except (KeyError, TypeError):
183 return cls.__new__(cls, name=None, value=value)
184
185 @classmethod
186 def from_string(cls, name: str) -> Self:

Callers 2

_postprocess_singleMethod · 0.80
test_try_valueFunction · 0.80

Calls 1

__new__Method · 0.45

Tested by 1

test_try_valueFunction · 0.64