gh-112559: Avoid unnecessary conversion attempts to enum_klass in signal.py (#113040)

This commit is contained in:
Yilei Yang 2023-12-23 17:07:52 -08:00 committed by GitHub
parent 0187a7e4ec
commit 050783cb37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 2 deletions

View file

@ -22,9 +22,11 @@ if 'pthread_sigmask' in _globals:
def _int_to_enum(value, enum_klass):
"""Convert a numeric value to an IntEnum member.
If it's not a known member, return the numeric value itself.
"""Convert a possible numeric value to an IntEnum member.
If it's not a known member, return the value itself.
"""
if not isinstance(value, int):
return value
try:
return enum_klass(value)
except ValueError: