Skip to content

Commit c5dfbd1

Browse files
authored
LaTeX plugin: fix type check (#448)
* Fix bug introduced in f7b2e69. Here checking exactly for Block is important; classes derived from Block must not match. * Fix conversion to string. * Linting.
1 parent 4aafd62 commit c5dfbd1

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

v7/latex/latex/parser.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,12 @@ def __flatten(self, block):
338338
if isinstance(block, tree.Block):
339339
while True:
340340
if len(block.elements) == 1 and isinstance(block.elements[0], tree.Block):
341-
if isinstance(block, tree.Block):
341+
# Note that the two if conditions below cannot use isinstance()
342+
# since we do not want to match any class derived from Block!
343+
if type(block) is tree.Block:
342344
block.elements[0].labels.extend(block.labels)
343345
block = block.elements[0]
344-
elif isinstance(block.elements[0], tree.Block):
346+
elif type(block.elements[0]) is tree.Block:
345347
block.labels.extend(block.elements[0].labels)
346348
block.elements = block.elements[0].elements
347349
else:

v7/latex/latex/tree.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def recombine_as_text(self, reescape=True):
341341

342342
def __str__(self):
343343
"""Generate textual representation."""
344-
return "TikzPicture(" + self.args + "; " + repr(self.formula) + ")"
344+
return "TikzPicture(" + str(self.args) + "; " + repr(self.formula) + ")"
345345

346346
def visit(self, visitor, *args, **kw):
347347
"""Process with TreeVisitor object. Passes ``args`` and ``kw`` to the corresponding method of ``visitor``."""

0 commit comments

Comments
 (0)