Skip to content
Open
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
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.11', '3.12', '3.13', '3.14-dev']
python-version: ['3.11', '3.12', '3.13', '3.14', '3.15']
qt-version: [5, 6]
qt-binding: [pyqt]
exclude:
Expand All @@ -33,7 +33,9 @@ jobs:
qt-version: 5
- python-version: '3.13'
qt-version: 5
- python-version: '3.14-dev'
- python-version: '3.14'
qt-version: 5
- python-version: '3.15'
qt-version: 5
fail-fast: false
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
python -m pip install wheel cibuildwheel
- name: Build wheels
env:
CIBW_BUILD: "cp311-* cp312-* cp313-* cp314-*"
CIBW_BUILD: "cp311-* cp312-* cp313-* cp314-* cp315-*"
CIBW_ARCHS_MACOS: x86_64 universal2 arm64
CIBW_ARCHS_WINDOWS: auto64
CIBW_TEST_REQUIRES: pytest
Expand Down
2 changes: 2 additions & 0 deletions enaml/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

PY314 = sys.version_info >= (3, 14)

PY315 = sys.version_info >= (3, 15)

# Functions used to update the co_filename slot of a code object
# Available in Python 3.5+ (tested up to 3.8)
from _imp import _fix_co_filename
Expand Down
57 changes: 48 additions & 9 deletions enaml/core/code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,37 @@
import bytecode as bc
from atom.api import Atom, Bool, Int, List, Str

from ..compat import PY312, PY313, PY314
try:
from bytecode.instr import CommonConstant
except ImportError: # pragma: no cover
CommonConstant = None

from ..compat import PY312, PY313, PY314, PY315


def _common_const(value):
"""Return the matching common-constant enum for the given singleton."""
if CommonConstant is None:
return None
if value is None:
return CommonConstant.CONSTANT_NONE
if value is False:
return CommonConstant.CONSTANT_FALSE
if value is True:
return CommonConstant.CONSTANT_TRUE
if value == "":
return CommonConstant.CONSTANT_EMPTY_STR
if value == -1:
return CommonConstant.CONSTANT_MINUS_ONE
return None


def _load_const_instr(value):
"""Build the appropriate constant-load instruction for the active Python."""
common = _common_const(value) if PY315 else None
if common is not None:
return bc.Instr("LOAD_COMMON_CONSTANT", common)
return bc.Instr("LOAD_CONST", value)


class _ReturnNoneIdentifier(ast.NodeVisitor):
Expand Down Expand Up @@ -153,7 +183,7 @@ def load_fast(self, name):
def load_const(self, const):
"""Load a const value onto the TOS."""
self.code_ops.append( # TOS
bc.Instr("LOAD_CONST", const), # TOS -> value
_load_const_instr(const), # TOS -> value
)

def load_attr(self, name):
Expand Down Expand Up @@ -218,6 +248,7 @@ def return_value(self):
if (
not PY314
and PY312
and not PY315
and self.code_ops
and self.code_ops[-1].name == "LOAD_CONST"
):
Expand Down Expand Up @@ -428,7 +459,7 @@ def try_squash_raise(self):
bc.Instr("JUMP_FORWARD", end_label),
# Under Python 3.11 only the actual exception is pushed
exc_label, # TOS -> val
bc.Instr("LOAD_CONST", None), # TOS -> val -> None
_load_const_instr(None), # TOS -> val -> None
bc.Instr("COPY", 2), # TOS -> val -> None -> val
bc.Instr("STORE_ATTR", "__traceback__"), # TOS -> val
bc.Instr("RAISE_VARARGS", 1),
Expand Down Expand Up @@ -477,12 +508,10 @@ def for_loop(self, iter_var, fast_var=True):
if PY312
else bc.Instr("JUMP_ABSOLUTE", start_label),
jump_label,
bc.Instr("POP_BLOCK"),
end_label,
]
)
self.code_ops.extend(
bc.Instr("POP_BLOCK"),
end_label,
)
if PY312:
self.code_ops.append(bc.Instr("END_FOR"))

Expand All @@ -505,8 +534,17 @@ def insert_python_block(self, pydata, trim=True):
(rc := (block[-1].name == "RETURN_CONST" and block[-1].arg is None))
or (
block[-1].name == "RETURN_VALUE"
and block[-2].name == "LOAD_CONST"
and block[-2].arg is None
and len(block) >= 2
and isinstance(block[-2], bc.Instr)
and (
(
PY315
and block[-2].name == "LOAD_COMMON_CONSTANT"
and block[-2].arg == CommonConstant.CONSTANT_NONE
)
# The dual check on py315 is sub-optimal
or (block[-2].name == "LOAD_CONST" and block[-2].arg is None)
)
and block[-1].lineno not in _inspector.lines
)
):
Expand Down Expand Up @@ -537,6 +575,7 @@ def insert_python_expr(self, pydata, trim=True):
bc_code = bc.Bytecode.from_code(code)
# Trim irrelevant RESUME opcode
bc_code = bc_code[1:]
assert isinstance(bc_code[-1], bc.Instr)
if bc_code[-1].name == "RETURN_CONST":
bc_code[-1] = bc.Instr(
"LOAD_CONST", bc_code[-1].arg, location=bc_code[-1].location
Expand Down
7 changes: 4 additions & 3 deletions enaml/core/compiler_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import bytecode as bc
from atom.api import Str, Typed

from ..compat import PY312, PY313, PY314
from ..compat import PY312, PY313, PY314, PY315
from .code_generator import CodeGenerator
from .enaml_ast import (
AliasExpr, ASTVisitor, Binding, ChildDef, EnamlDef, StorageExpr, Template,
Expand Down Expand Up @@ -913,8 +913,9 @@ def _insert_decl_function(cg, funcdef):

# convert to a bytecode object and remove the leading and
# trailing ops: STORE_NAME LOAD_CONST RETURN_VALUE
# Python 3.12 uses RETURN_CONST
outer_ops = bc.Bytecode.from_code(code)[0:(-2 if not PY314 and PY312 else -3)]
# Python 3.12 uses RETURN_CONST and Python 3.15 uses LOAD_COMMON_CONSTANT
# for None.
outer_ops = bc.Bytecode.from_code(code)[0:(-2 if (PY312 and not PY314 and not PY315) else -3)]

# On 3.14 if the function has annotations it looks like
# ...
Expand Down
5 changes: 3 additions & 2 deletions enaml/core/import_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import io
import struct
import sys
from abc import ABCMeta, abstractmethod, abstractclassmethod
from abc import ABCMeta, abstractmethod
from collections import defaultdict, namedtuple
from zipfile import ZipFile

Expand Down Expand Up @@ -147,7 +147,8 @@ def exec_module(self, module, code=None):
#--------------------------------------------------------------------------
# Abstract API
#--------------------------------------------------------------------------
@abstractclassmethod
@classmethod
@abstractmethod
def locate_module(cls, fullname, path=None):
""" Searches for the given Enaml module and returns an instance
of AbstractEnamlImporter on success.
Expand Down
12 changes: 3 additions & 9 deletions enaml/core/parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ------------------------------------------------------------------------------
# Copyright (c) 2013-2025, Nucleic Development Team.
# Copyright (c) 2013-2026, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
Expand All @@ -8,7 +8,7 @@
import io
import os
import tokenize
from typing import Callable, Iterator, Optional, TextIO, Union
from typing import Callable, Iterator, Optional, TextIO

from pegen.tokenizer import Tokenizer

Expand All @@ -31,7 +31,7 @@ def _parse(
else tokenize.generate_tokens(stream.readline)
)
tokenizer = Tokenizer(
tok_stream, verbose=verbose, path=path if os.path.isfile(path) else None
tok_stream, verbose=verbose, path=path if os.path.isfile(path) else ""
)
parser = EnamlParser(
tokenizer,
Expand All @@ -42,7 +42,6 @@ def _parse(
return parser.parse("start")


# XXX document
# filename is named so for backward compatibility
def parse(
source: str,
Expand All @@ -58,12 +57,7 @@ def parse(
This function is meant for in memory sources and one should prefer parse_file
for sources existing in a file.

Parameters
----------


"""
return _parse(
io.StringIO(source), filename, py_version, token_stream_factory, verbose
)

18 changes: 9 additions & 9 deletions enaml/core/parser/base_enaml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ def create_python_func_for_operator(
self.raise_syntax_error_known_location(msg, item)

func_node = ast.FunctionDef(
name = "f",
args = self.make_arguments(None, [], None, None, None),
decorator_list = [],
returns = None,
body = body,
lineno = body[0].lineno,
col_offset = body[0].col_offset,
end_lineno = body[-1].end_lineno,
end_col_offset = body[-1].end_col_offset,
name="f",
args=self.make_arguments(None, [], None, None, None),
decorator_list=[],
returns=None,
body=body,
lineno=body[0].lineno,
col_offset=body[0].col_offset,
end_lineno=body[-1].end_lineno,
end_col_offset=body[-1].end_col_offset,
)

return self.create_python_module([func_node])
Expand Down
Loading
Loading