Skip to content

Commit

Permalink
refactor: don't use the same variable name for different types (#2523)
Browse files Browse the repository at this point in the history
Mypy does not like it when the same variable name is used for different
types.
  • Loading branch information
aucampia authored Aug 10, 2023
1 parent f45bd9b commit d163c2e
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions rdflib/plugins/sparql/algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,10 @@ def triples(
List[List[Identifier]], List[Tuple[Identifier, Identifier, Identifier]]
]
) -> List[Tuple[Identifier, Identifier, Identifier]]:
# NOTE on type errors: errors are a result of the variable being reused for
# a different type.
# type error: Incompatible types in assignment (expression has type "Sequence[Identifier]", variable has type "Union[List[List[Identifier]], List[Tuple[Identifier, Identifier, Identifier]]]")
l = reduce(lambda x, y: x + y, l) # type: ignore[assignment] # noqa: E741
if (len(l) % 3) != 0:
_l = reduce(lambda x, y: x + y, l)
if (len(_l) % 3) != 0:
raise Exception("these aint triples")
# type error: Generator has incompatible item type "Tuple[Union[List[Identifier], Tuple[Identifier, Identifier, Identifier]], Union[List[Identifier], Tuple[Identifier, Identifier, Identifier]], Union[List[Identifier], Tuple[Identifier, Identifier, Identifier]]]"; expected "Tuple[Identifier, Identifier, Identifier]"
return reorderTriples((l[x], l[x + 1], l[x + 2]) for x in range(0, len(l), 3)) # type: ignore[misc]
return reorderTriples((_l[x], _l[x + 1], _l[x + 2]) for x in range(0, len(_l), 3))


# type error: Missing return statement
Expand Down

0 comments on commit d163c2e

Please sign in to comment.