Skip to content

Commit

Permalink
LaTeX plugin: fix type check (#448)
Browse files Browse the repository at this point in the history
* Fix bug introduced in f7b2e69.

Here checking exactly for Block is important; classes derived
from Block must not match.

* Fix conversion to string.

* Linting.
  • Loading branch information
felixfontein authored Nov 2, 2024
1 parent 4aafd62 commit c5dfbd1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions v7/latex/latex/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,12 @@ def __flatten(self, block):
if isinstance(block, tree.Block):
while True:
if len(block.elements) == 1 and isinstance(block.elements[0], tree.Block):
if isinstance(block, tree.Block):
# Note that the two if conditions below cannot use isinstance()
# since we do not want to match any class derived from Block!
if type(block) is tree.Block:
block.elements[0].labels.extend(block.labels)
block = block.elements[0]
elif isinstance(block.elements[0], tree.Block):
elif type(block.elements[0]) is tree.Block:
block.labels.extend(block.elements[0].labels)
block.elements = block.elements[0].elements
else:
Expand Down
2 changes: 1 addition & 1 deletion v7/latex/latex/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def recombine_as_text(self, reescape=True):

def __str__(self):
"""Generate textual representation."""
return "TikzPicture(" + self.args + "; " + repr(self.formula) + ")"
return "TikzPicture(" + str(self.args) + "; " + repr(self.formula) + ")"

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

0 comments on commit c5dfbd1

Please sign in to comment.