Skip to content

Commit

Permalink
misc: add pyright ignores for places where it's not going to be happy (
Browse files Browse the repository at this point in the history
…#3263)

Pyright used to be happy to accept type expressions as types, but is
happy no longer. This adds the required pyright ignores to work around
this restriction.

Pylance errors: 94 -> 81
  • Loading branch information
superlopuh authored Oct 9, 2024
1 parent 27bd5c4 commit de770bf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
24 changes: 12 additions & 12 deletions tests/test_is_satisfying_hint.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,18 +372,18 @@ def test_parametrized_attribute():


def test_literal():
assert isa("string", Literal["string"])
assert isa("string", Literal["string", "another string"])
assert isa("another string", Literal["string", "another string"])
assert not isa("not this string", Literal["string", "another string"])

assert isa(1, Literal[1])
assert isa(1, Literal[1, 2])
assert isa(2, Literal[1, 2])
assert not isa(3, Literal[1, 2])

assert not isa(1, Literal["1"])
assert not isa("1", Literal[1])
assert isa("string", Literal["string"]) # pyright: ignore[reportArgumentType]
assert isa("string", Literal["string", "another string"]) # pyright: ignore[reportArgumentType]
assert isa("another string", Literal["string", "another string"]) # pyright: ignore[reportArgumentType]
assert not isa("not this string", Literal["string", "another string"]) # pyright: ignore[reportArgumentType]

assert isa(1, Literal[1]) # pyright: ignore[reportArgumentType]
assert isa(1, Literal[1, 2]) # pyright: ignore[reportArgumentType]
assert isa(2, Literal[1, 2]) # pyright: ignore[reportArgumentType]
assert not isa(3, Literal[1, 2]) # pyright: ignore[reportArgumentType]

assert not isa(1, Literal["1"]) # pyright: ignore[reportArgumentType]
assert not isa("1", Literal[1]) # pyright: ignore[reportArgumentType]


################################################################################
Expand Down
4 changes: 1 addition & 3 deletions xdsl/tools/tblgen_to_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def generate_op(self, tblgen_op: TblgenOp, dialect_name: str):
"SizedRegion" in region.superclasses
and region.summary == "region with 1 blocks"
)
match (variadic, single_block):
match (variadic, single_block): # pyright: ignore[reportMatchNotExhaustive]
case (False, False):
fields[name] = "region_def()"
case (False, True):
Expand All @@ -474,8 +474,6 @@ def generate_op(self, tblgen_op: TblgenOp, dialect_name: str):
fields[name] = "var_region_def()"
case (True, True):
fields[name] = 'var_region_def("single_block")'
case _:
pass # Make pyright happy

for [succ, name] in tblgen_op.successors:
name = self._resolve_name(name)
Expand Down
2 changes: 1 addition & 1 deletion xdsl/utils/hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def isa(arg: Any, hint: type[_T]) -> TypeGuard[_T]:
For now, only lists, dictionaries, unions,
and non-generic classes are supported for type hints.
"""
if hint is Any:
if hint is Any: # pyright: ignore[reportUnnecessaryComparison]
return True

origin = get_origin(hint)
Expand Down

0 comments on commit de770bf

Please sign in to comment.