Skip to content

Commit cf1d586

Browse files
committed
chore(release): bump version to 6.0.7 and improve import_hook typing (main)
- Bump project version to 6.0.7 in pyproject.toml - Add type annotations to source_to_code in import_hook.py - Improve bytes/str handling for AST parsing and regex checks
1 parent 43f159a commit cf1d586

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ egg_info.egg_base = "build"
1212

1313
[project]
1414
name = "pynesys-pynecore"
15-
version = "6.0.6" # PineVersion.Major.Minor
15+
version = "6.0.7" # PineVersion.Major.Minor
1616
description = "Python based Pine Script like runtime and API"
1717
authors = [{ name = "PYNESYS LLC", email = "hello@pynesys.com" }]
1818
readme = "README.md"
1919
requires-python = ">=3.11"
20-
license = {text = "Apache-2.0"}
20+
license = { text = "Apache-2.0" }
2121
classifiers = [
2222
"Programming Language :: Python :: 3",
2323
"Operating System :: OS Independent",

src/pynecore/core/import_hook.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class PyneLoader(importlib.machinery.SourceFileLoader):
1212
"""Loader that handles AST transformation"""
1313

1414
# noinspection PyMethodOverriding
15-
def source_to_code(self, data, path, *, _optimize=-1):
15+
def source_to_code(self, data: bytes | str, path: str, *, _optimize: int = -1):
1616
"""Transform source to code if needed"""
1717
path = Path(path)
1818

@@ -29,12 +29,13 @@ def source_to_code(self, data, path, *, _optimize=-1):
2929

3030
# Fast check for @pyne decorator before parsing AST
3131
# data is bytes, need to convert to string for regex
32-
if not re.search(r'@pyne\b', data.decode('utf-8')):
32+
data_str = data.decode('utf-8') if isinstance(data, bytes) else data
33+
if not re.search(r'@pyne\b', data_str):
3334
# No @pyne decorator, let Python handle it normally
3435
return compile(data, path, 'exec', optimize=_optimize)
3536

3637
# Parse AST only if @pyne is present
37-
tree = ast.parse(data)
38+
tree = ast.parse(data_str)
3839

3940
# Store file path in AST for transformers
4041
tree._module_file_path = str(path.resolve()) # type: ignore

0 commit comments

Comments
 (0)