Returns the string representation of the underlying type. This function is almost equivalent to running `repr(self.value)`, except it includes some additional logic to correctly handle cases where the value is a string, byte string, a unicode string, or an enum.
(self)
| 3252 | return self.fallback.type.is_enum |
| 3253 | |
| 3254 | def value_repr(self) -> str: |
| 3255 | """Returns the string representation of the underlying type. |
| 3256 | |
| 3257 | This function is almost equivalent to running `repr(self.value)`, |
| 3258 | except it includes some additional logic to correctly handle cases |
| 3259 | where the value is a string, byte string, a unicode string, or an enum. |
| 3260 | """ |
| 3261 | raw = repr(self.value) |
| 3262 | fallback_name = self.fallback.type.fullname |
| 3263 | |
| 3264 | # If this is backed by an enum, |
| 3265 | if self.is_enum_literal(): |
| 3266 | return f"{fallback_name}.{self.value}" |
| 3267 | |
| 3268 | if fallback_name == "builtins.bytes": |
| 3269 | # Note: 'builtins.bytes' only appears in Python 3, so we want to |
| 3270 | # explicitly prefix with a "b" |
| 3271 | return "b" + raw |
| 3272 | else: |
| 3273 | # 'builtins.str' could mean either depending on context, but either way |
| 3274 | # we don't prefix: it's the "native" string. And of course, if value is |
| 3275 | # some other type, we just return that string repr directly. |
| 3276 | return raw |
| 3277 | |
| 3278 | def serialize(self) -> JsonDict | str: |
| 3279 | return { |
no test coverage detected