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

_plequal: marginally reduce cyclomatic complexity #223

Merged
merged 2 commits into from
Dec 28, 2024
Merged
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
22 changes: 9 additions & 13 deletions inflect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2572,20 +2572,16 @@ def singular_noun(
return f"{pre}{plural}{post}"
return False

def _plequal(self, word1: str, word2: str, pl) -> Union[str, bool]: # noqa: C901
def _plequal(self, word1: str, word2: str, pl) -> Union[str, bool]:
classval = self.classical_dict.copy()
self.classical_dict = all_classical.copy()
if word1 == word2:
return "eq"
if word1 == pl(word2):
return "p:s"
if pl(word1) == word2:
return "s:p"
self.classical_dict = no_classical.copy()
if word1 == pl(word2):
return "p:s"
if pl(word1) == word2:
return "s:p"
for dictionary in (all_classical, no_classical):
self.classical_dict = dictionary.copy()
if word1 == word2:
return "eq"
if word1 == pl(word2):
return "p:s"
if pl(word1) == word2:
return "s:p"
self.classical_dict = classval.copy()

if pl == self.plural or pl == self.plural_noun:
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
Loading