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

Fix flake8 test regarding type checking #14

Closed
wants to merge 1 commit into from
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
28 changes: 14 additions & 14 deletions parsing/automaton.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def __hash__(self) -> int:
return self._hash

def __eq__(self, other: Any) -> bool:
if type(other) == ItemSet:
if type(other) is ItemSet:
return self._kernel.keys() == other._kernel.keys()
else:
return NotImplemented
Expand Down Expand Up @@ -589,7 +589,7 @@ def __repr__(self) -> str:
conflict = "XXX"
break

if type(action) == ShiftAction:
if type(action) is ShiftAction:
lines.append(
"%s %15r : %-6s %d [%s]"
% (
Expand All @@ -601,7 +601,7 @@ def __repr__(self) -> str:
)
)
else:
assert type(action) == ReduceAction
assert type(action) is ReduceAction
lines.append(
"%s %15r : %-6s %r"
% (conflict, sym, "reduce", action.production)
Expand Down Expand Up @@ -1715,16 +1715,16 @@ def _resolve(
) -> ConflictResolution:
ret: ConflictResolution

if type(oldAct) == ShiftAction:
if type(oldAct) is ShiftAction:
oldPrec = sym.prec
elif type(oldAct) == ReduceAction:
elif type(oldAct) is ReduceAction:
oldPrec = oldAct.production.prec
else:
assert False

if type(newAct) == ShiftAction:
if type(newAct) is ShiftAction:
newPrec = sym.prec
elif type(newAct) == ReduceAction:
elif type(newAct) is ReduceAction:
newPrec = newAct.production.prec
else:
assert False
Expand All @@ -1740,9 +1740,9 @@ def _resolve(

if oldPrec.assoc == "split" or newPrec.assoc == "split":
ret = "both"
elif type(newAct) == type(oldAct):
assert type(newAct) == ReduceAction
assert type(oldAct) == ReduceAction
elif type(newAct) is type(oldAct):
assert type(newAct) is ReduceAction
assert type(oldAct) is ReduceAction
# Fatal reduce/reduce conflict.
ret = "err"
else:
Expand All @@ -1765,16 +1765,16 @@ def _resolve(
if assoc == "fail":
ret = "err"
elif assoc == "left":
if type(oldAct) == ShiftAction:
if type(oldAct) is ShiftAction:
ret = "new"
else:
assert type(newAct) == ShiftAction
assert type(newAct) is ShiftAction
ret = "old"
elif assoc == "right":
if type(oldAct) == ShiftAction:
if type(oldAct) is ShiftAction:
ret = "old"
else:
assert type(newAct) == ShiftAction
assert type(newAct) is ShiftAction
ret = "new"
elif assoc == "nonassoc":
ret = "neither"
Expand Down
6 changes: 3 additions & 3 deletions parsing/glrparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def _reductions(self, sym: Token, symSpec: TokenSpec) -> None:
self._gss.pop(i)
else:
for action in self._action[top.nextState][symSpec]:
if type(action) == ReduceAction:
if type(action) is ReduceAction:
if len(action.production.rhs) == 0:
if action.production not in epsilons:
assert (
Expand Down Expand Up @@ -324,7 +324,7 @@ def _enqueueLimitedReductions(
for top in self._gss:
if symSpec in self._action[top.nextState]:
for action in self._action[top.nextState][symSpec]:
if type(action) == ReduceAction:
if type(action) is ReduceAction:
if len(action.production.rhs) == 0:
if (
gotos[top.nextState][action.production.lhs]
Expand Down Expand Up @@ -377,7 +377,7 @@ def _shifts(self, sym: Token, symSpec: TokenSpec) -> None:
for topA in prevGss:
if symSpec in self._action[topA.nextState]:
for action in self._action[topA.nextState][symSpec]:
if type(action) == ShiftAction:
if type(action) is ShiftAction:
merged = False
for topB in self._gss:
if topB.nextState == topA.nextState:
Expand Down
6 changes: 3 additions & 3 deletions parsing/lrparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Lr(Parser):

def __init__(self, spec: Spec) -> None:
if __debug__:
if type(self) == Lr:
if type(self) is Lr:
assert spec.pureLR
assert spec.conflicts == 0
self._spec = spec
Expand Down Expand Up @@ -86,11 +86,11 @@ def _act(self, sym: Token, symSpec: TokenSpec) -> None:

if self.verbose:
print(" --> %r" % action)
if type(action) == ShiftAction:
if type(action) is ShiftAction:
self._stack.append((sym, action.nextState))
break
else:
assert type(action) == ReduceAction
assert type(action) is ReduceAction
self._reduce(action.production)

if self.verbose:
Expand Down
Loading