Skip to content

Commit

Permalink
core: avoid generating empty block when trimming bytecode blocks (#476)
Browse files Browse the repository at this point in the history
* core: avoid generating empty block when trimming bytecode blocks

* tests: add test for bytecode generation

* update release notes

* appveyor: run on Python 3.8
  • Loading branch information
MatthieuDartiailh committed Feb 7, 2022
1 parent 5be91cd commit b849cf7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
8 changes: 4 additions & 4 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ environment:
# 32-bit versions, PyQt and PySide2, latest

- NAME: "32-bit, Latest "
PYTHON: "C:\\Python37"
PYTHON_VERSION: "3.7.3"
PYTHON: "C:\\Python38"
PYTHON_VERSION: "3.9"
PYTHON_ARCH: "32"
PYQT_VERSION: "5"

- NAME: "PySide2"
PYTHON: "C:\\Python37-x64"
PYTHON_VERSION: "3.7.3"
PYTHON: "C:\\Python38"
PYTHON_VERSION: "3.9"
PYTHON_ARCH: "32"
PYQT_VERSION: "None"
QT_API: "pyside2"
Expand Down
4 changes: 4 additions & 0 deletions enaml/core/code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ def insert_python_block(self, pydata, trim=True):
and block[-1].lineno not in _inspector.lines
):
del block[-2:]
# If as a result of the trimming the block is empty, we add
# a NOP to make sure it is valid still
if not any(isinstance(i, bc.Instr) for i in block):
block.append(bc.Instr("NOP"))
# If we have multiple block jump to the end of the last block
# to execute the code that may be appended to this block
if block is not last_block:
Expand Down
3 changes: 2 additions & 1 deletion releasenotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ Enaml Release Notes

Dates are written as DD/MM/YYYY

0.15.0 - Unreleased
0.14.1 - Unreleased
-------------------
- fixes a bug in code generation for Pythoon 3.10 PR #476
- fixes several bugs in corner cases of the Qt dock area PR #469
- add python fstring scintilla tokens PR #470
- address PyQt deprecation of accepting float values for pixel dimensions PR #471
Expand Down
2 changes: 2 additions & 0 deletions tests/core/test_code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# encounter a non-implicit return opcode.
@pytest.mark.parametrize("source, return_on_lines", [
("pass", []),
("if a:\n print("")", []),
("for i in range(10):\n i", []),
("with open(f) as f:\n print(f.readlines())", []),
])
Expand All @@ -25,3 +26,4 @@ def test_python_block_insertion(source, return_on_lines):
for i in cg.code_ops:
if getattr(i, "name", "") == "RETURN_VALUE":
assert i.lineno in return_on_lines
cg.to_code()

0 comments on commit b849cf7

Please sign in to comment.