support python 3.10 (#450)

* support python 3.10

* add 3.10 to tests

* new StrEnum
This commit is contained in:
Oliver Stanley 2025-06-04 10:34:01 +01:00 committed by GitHub
parent 84958baa69
commit 1a727ecf4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 49 additions and 12 deletions

View file

@ -1,6 +1,7 @@
import math
import re
from decimal import Decimal, InvalidOperation
from enum import Enum
from fractions import Fraction
from typing import Any, Optional, Union
@ -117,3 +118,38 @@ def compute_decimal_reward(answer: Optional[str], oracle_answer: str, strip_comm
reward = len(oracle_answer) / len(answer)
return reward
class StrEnum(str, Enum):
"""
Taken from Python 3.11 StrEnum implementation, moved here to support Python 3.10.
Enum where members are also (and must be) strings
"""
def __new__(cls, *values):
"values must already be of type `str`"
if len(values) > 3:
raise TypeError("too many arguments for str(): %r" % (values,))
if len(values) == 1:
# it must be a string
if not isinstance(values[0], str):
raise TypeError("%r is not a string" % (values[0],))
if len(values) >= 2:
# check that encoding argument is a string
if not isinstance(values[1], str):
raise TypeError("encoding must be a string, not %r" % (values[1],))
if len(values) == 3:
# check that errors argument is a string
if not isinstance(values[2], str):
raise TypeError("errors must be a string, not %r" % (values[2]))
value = str(*values)
member = str.__new__(cls, value)
member._value_ = value
return member
@staticmethod
def _generate_next_value_(name, start, count, last_values):
"""
Return the lower-cased version of the member name.
"""
return name.lower()