Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

engine: migrate from py3.14-removed 'ast' classes #225

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions inflect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2264,19 +2264,13 @@ def _get_value_from_ast(self, obj):
"""
Return the value of the ast object.
"""
if isinstance(obj, ast.Num):
return obj.n
elif isinstance(obj, ast.Str):
return obj.s
if isinstance(obj, ast.Constant):
return obj.value
elif isinstance(obj, ast.List):
return [self._get_value_from_ast(e) for e in obj.elts]
elif isinstance(obj, ast.Tuple):
return tuple([self._get_value_from_ast(e) for e in obj.elts])

# None, True and False are NameConstants in Py3.4 and above.
elif isinstance(obj, ast.NameConstant):
return obj.value

# Probably passed a variable name.
# Or passed a single word without wrapping it in quotes as an argument
# ex: p.inflect("I plural(see)") instead of p.inflect("I plural('see')")
Expand Down
12 changes: 6 additions & 6 deletions tests/test_classical_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ def test_classical(self):
# DEFAULT...

assert p.plural_noun("error", 0) == "errors", "classical 'zero' not active"
assert (
p.plural_noun("wildebeest") == "wildebeests"
), "classical 'herd' not active"
assert p.plural_noun("wildebeest") == "wildebeests", (
"classical 'herd' not active"
)
assert p.plural_noun("Sally") == "Sallys", "classical 'names' active"
assert p.plural_noun("brother") == "brothers", "classical others not active"
assert p.plural_noun("person") == "people", "classical 'persons' not active"
Expand All @@ -30,9 +30,9 @@ def test_classical(self):

p.classical(all=False)
assert p.plural_noun("error", 0) == "errors", "classical 'zero' not active"
assert (
p.plural_noun("wildebeest") == "wildebeests"
), "classical 'herd' not active"
assert p.plural_noun("wildebeest") == "wildebeests", (
"classical 'herd' not active"
)
assert p.plural_noun("Sally") == "Sallies", "classical 'names' not active"
assert p.plural_noun("brother") == "brothers", "classical others not active"
assert p.plural_noun("person") == "people", "classical 'persons' not active"
Expand Down
8 changes: 4 additions & 4 deletions tests/test_numwords.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,19 @@ def test_array():
],
[
"123456",
"one hundred and twenty-three thousand, " "four hundred and fifty-six",
"one hundred and twenty-three thousand, four hundred and fifty-six",
"one, two, three, four, five, six",
"twelve, thirty-four, fifty-six",
"one twenty-three, four fifty-six",
"one hundred and twenty-three thousand, " "four hundred and fifty-sixth",
"one hundred and twenty-three thousand, four hundred and fifty-sixth",
],
[
"0123456",
"one hundred and twenty-three thousand, " "four hundred and fifty-six",
"one hundred and twenty-three thousand, four hundred and fifty-six",
"zero, one, two, three, four, five, six",
"zero one, twenty-three, forty-five, six",
"zero twelve, three forty-five, six",
"one hundred and twenty-three thousand, " "four hundred and fifty-sixth",
"one hundred and twenty-three thousand, four hundred and fifty-sixth",
],
[
"1234567",
Expand Down
36 changes: 18 additions & 18 deletions tests/test_pwd.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ def test_pl(self):
(p.plural_adj, "cat's", "cats'"),
(p.plural_adj, "child's", "children's"),
):
assert (
fn(sing) == plur
), f'{fn.__name__}("{sing}") == "{fn(sing)}" != "{plur}"'
assert fn(sing) == plur, (
f'{fn.__name__}("{sing}") == "{fn(sing)}" != "{plur}"'
)

for sing, num, plur in (
("cow", 1, "cow"),
Expand Down Expand Up @@ -341,9 +341,9 @@ def test_gender(self):
("to her", "to them"),
("to herself", "to themselves"),
):
assert (
p.singular_noun(plur) == sing
), f"singular_noun({plur}) == {p.singular_noun(plur)} != {sing}"
assert p.singular_noun(plur) == sing, (
f"singular_noun({plur}) == {p.singular_noun(plur)} != {sing}"
)
assert p.inflect("singular_noun('%s')" % plur) == sing

p.gender("masculine")
Expand All @@ -354,9 +354,9 @@ def test_gender(self):
("to him", "to them"),
("to himself", "to themselves"),
):
assert (
p.singular_noun(plur) == sing
), f"singular_noun({plur}) == {p.singular_noun(plur)} != {sing}"
assert p.singular_noun(plur) == sing, (
f"singular_noun({plur}) == {p.singular_noun(plur)} != {sing}"
)
assert p.inflect("singular_noun('%s')" % plur) == sing

p.gender("gender-neutral")
Expand All @@ -367,9 +367,9 @@ def test_gender(self):
("to them", "to them"),
("to themself", "to themselves"),
):
assert (
p.singular_noun(plur) == sing
), f"singular_noun({plur}) == {p.singular_noun(plur)} != {sing}"
assert p.singular_noun(plur) == sing, (
f"singular_noun({plur}) == {p.singular_noun(plur)} != {sing}"
)
assert p.inflect("singular_noun('%s')" % plur) == sing

p.gender("neuter")
Expand All @@ -380,9 +380,9 @@ def test_gender(self):
("to it", "to them"),
("to itself", "to themselves"),
):
assert (
p.singular_noun(plur) == sing
), f"singular_noun({plur}) == {p.singular_noun(plur)} != {sing}"
assert p.singular_noun(plur) == sing, (
f"singular_noun({plur}) == {p.singular_noun(plur)} != {sing}"
)
assert p.inflect("singular_noun('%s')" % plur) == sing

with pytest.raises(BadGenderError):
Expand Down Expand Up @@ -612,9 +612,9 @@ def test__plnoun(self):
("zoo", "zoos"),
("tomato", "tomatoes"),
):
assert (
p._plnoun(sing) == plur
), f'p._plnoun("{sing}") == {p._plnoun(sing)} != "{plur}"'
assert p._plnoun(sing) == plur, (
f'p._plnoun("{sing}") == {p._plnoun(sing)} != "{plur}"'
)

assert p._sinoun(plur) == sing, f'p._sinoun("{plur}") != "{sing}"'

Expand Down