From a780056678b1b340eb63f7c63a84e4ad9cfc3ccb Mon Sep 17 00:00:00 2001 From: Vyacheslav Tamarin Date: Tue, 14 Nov 2023 14:35:19 +0300 Subject: [PATCH 1/2] Fix instructions for 3.9- --- .../utbot_executor/utbot_executor/executor.py | 2 +- .../utbot_executor/utbot_executor/utils.py | 21 ++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/utbot-python-executor/src/main/python/utbot_executor/utbot_executor/executor.py b/utbot-python-executor/src/main/python/utbot_executor/utbot_executor/executor.py index 01fdb290d4..5bedef3896 100644 --- a/utbot-python-executor/src/main/python/utbot_executor/utbot_executor/executor.py +++ b/utbot-python-executor/src/main/python/utbot_executor/utbot_executor/executor.py @@ -182,7 +182,7 @@ def _run_calculate_function_value( __is_exception = False _, __start = inspect.getsourcelines(function) - __all_code_stmts = filter_instructions(get_instructions(function.__code__), tracer.mode) + __all_code_stmts = filter_instructions(get_instructions(function), tracer.mode) __tracer = tracer diff --git a/utbot-python-executor/src/main/python/utbot_executor/utbot_executor/utils.py b/utbot-python-executor/src/main/python/utbot_executor/utbot_executor/utils.py index d3f6d14700..f5b156c0b6 100644 --- a/utbot-python-executor/src/main/python/utbot_executor/utbot_executor/utils.py +++ b/utbot-python-executor/src/main/python/utbot_executor/utbot_executor/utils.py @@ -1,11 +1,15 @@ from __future__ import annotations import dataclasses +import dis import enum import os import sys import typing from contextlib import contextmanager -from types import CodeType +from types import CodeType, MethodType, FunctionType, LambdaType + + +InstructionType: typing.TypeAlias = MethodType | FunctionType | CodeType | type | LambdaType class TraceMode(enum.Enum): @@ -37,8 +41,19 @@ def suppress_stdout(): sys.stdout = old_stdout -def get_instructions(obj: CodeType) -> list[UtInstruction]: - return [UtInstruction(line, start_offset, True) for start_offset, _, line in obj.co_lines() if None not in {start_offset, line}] +def get_instructions(obj: InstructionType) -> list[UtInstruction]: + if sys.version_info >= (3, 10): + code = obj.__code__ + return [UtInstruction(line, start_offset, True) for start_offset, _, line in code.co_lines() if None not in {start_offset, line}] + else: + instructions: list[UtInstruction] = [] + current_line = None + for instruction in dis.get_instructions(obj): + if current_line is None and instruction.starts_line: + current_line = instruction.starts_line + if current_line is not None: + instructions.append(UtInstruction(instruction.starts_line, instruction.offset, True)) + return instructions def filter_instructions( From 6acb5bdfe692313daf741149a59e7cdcefbbbcd3 Mon Sep 17 00:00:00 2001 From: Vyacheslav Tamarin Date: Thu, 23 Nov 2023 15:28:25 +0300 Subject: [PATCH 2/2] Update utbot_executor_version --- .../src/main/python/utbot_executor/pyproject.toml | 2 +- utbot-python-executor/src/main/resources/utbot_executor_version | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/utbot-python-executor/src/main/python/utbot_executor/pyproject.toml b/utbot-python-executor/src/main/python/utbot_executor/pyproject.toml index a1b7b52fd2..1775151def 100644 --- a/utbot-python-executor/src/main/python/utbot_executor/pyproject.toml +++ b/utbot-python-executor/src/main/python/utbot_executor/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "utbot-executor" -version = "1.8.0" +version = "1.8.6" description = "" authors = ["Vyacheslav Tamarin "] readme = "README.md" diff --git a/utbot-python-executor/src/main/resources/utbot_executor_version b/utbot-python-executor/src/main/resources/utbot_executor_version index afa2b3515e..9eadd6baad 100644 --- a/utbot-python-executor/src/main/resources/utbot_executor_version +++ b/utbot-python-executor/src/main/resources/utbot_executor_version @@ -1 +1 @@ -1.8.0 \ No newline at end of file +1.8.6 \ No newline at end of file