I’ve used mypy to type-check rbast.py
from this post:
https://mypy-play.net/?mypy=latest&python=3.12&gist=19931c644949c29b715b797a90b59a01
It gives three errors. The first two are obvious, but the third is:
main.py:38: error: Generator has incompatible item type "Sequence[str]"; expected "str" [misc]
How do I need to change the code to fix this error?
1
Here’s the problematic code:
for arg_repr in product(*arg_reprs, *kw_reprs):
arg_list = ", ".join(
f"{arg[0]}: {arg[1]}" if isinstance(arg, tuple) else arg
for arg in arg_repr
)
product
yields tuples, so arg
is a tuple. It’s not clear what if isinstance(arg, tuple) else arg
is for, you should be able to remove that whole snippet entirely. mypy’s problem seems to be that the else arg
might happen in which case your generator contains some tuples, not just strings.
2