1717from enum import Enum
1818from typing import Any
1919
20+ _PLATFORM_PYTHON_VERSION = platform .python_version ()
21+
2022
2123class ModuleSystem (str , Enum ):
2224 """Module system used by the code."""
@@ -189,6 +191,9 @@ class TestGenRequest:
189191
190192 def to_payload (self ) -> dict [str , Any ]:
191193 """Convert to API payload dict, maintaining backward compatibility."""
194+ # Backward compat: backend still expects python_version
195+ python_version = self .language_info .version if self .language_info .name == "python" else _PLATFORM_PYTHON_VERSION
196+
192197 payload = {
193198 "source_code_being_tested" : self .source_code ,
194199 "function_to_optimize" : {"function_name" : self .function_name , "is_async" : self .is_async },
@@ -203,18 +208,10 @@ def to_payload(self) -> dict[str, Any]:
203208 "codeflash_version" : self .codeflash_version ,
204209 "is_async" : self .is_async ,
205210 "is_numerical_code" : self .is_numerical_code ,
211+ "language_version" : self .language_info .version ,
212+ "python_version" : python_version ,
206213 }
207214
208- # Add language version (canonical for all languages)
209- payload ["language_version" ] = self .language_info .version
210-
211- # Backward compat: backend still expects python_version
212- import platform
213-
214- payload ["python_version" ] = (
215- self .language_info .version if self .language_info .name == "python" else platform .python_version ()
216- )
217-
218215 # Module system for JS/TS
219216 if self .language_info .module_system != ModuleSystem .UNKNOWN :
220217 payload ["module_system" ] = self .language_info .module_system .value
0 commit comments