Merge pull request #5719 from tk0miya/refactor_NodeMatcher

refactor NodeMatcher for mypy friendly
This commit is contained in:
Takeshi KOMIYA 2018-12-04 23:31:33 +09:00 committed by GitHub
commit de37ad76a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -68,18 +68,19 @@ class NodeMatcher:
if self.classes and not isinstance(node, self.classes):
return False
if self.attrs and isinstance(node, nodes.Text):
return False
if self.attrs:
if not isinstance(node, nodes.Element):
return False
for key, value in self.attrs.items():
if key not in node:
return False
elif value is Any:
continue
elif node.get(key) != value:
return False
else:
return True
for key, value in self.attrs.items():
if key not in node:
return False
elif value is Any:
continue
elif node.get(key) != value:
return False
return True
except Exception:
# for non-Element nodes
return False