Skip to content

Fix f-string syntax error causing import failure on Python ≤3.11 #20

@AlessLovato

Description

@AlessLovato

Issue Description

The library cannot be imported on Python versions ≤3.11 due to a malformed f-string that causes a syntax error during import.

Error Details

File: src/CognexNativePy/commands/SettingsAndCellsValues.py
Line: 217

Error Message:

SyntaxError: EOL while scanning string literal

Full Traceback:

Traceback (most recent call last):
  File ~/anaconda3/envs/env3.9/lib/python3.9/site-packages/IPython/core/interactiveshell.py:3550 in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  Cell In[2], line 1
    from CognexNativePy import NativeInterface
  File ~/anaconda3/envs/env3.9/lib/python3.9/site-packages/CognexNativePy/__init__.py:1
    from .NativeInterface import NativeInterface
  File ~/anaconda3/envs/env3.9/lib/python3.9/site-packages/CognexNativePy/NativeInterface.py:5
    from .commands.SettingsAndCellsValues import SettingsAndCellsValues
  File ~/anaconda3/envs/env3.9/lib/python3.9/site-packages/CognexNativePy/commands/SettingsAndCellsValues.py:210
    print(f'{isinstance(row_or_row_offset, (int, float))} {isinstance(row_offset_or_col_offset, float)} {
                                                                                                         ^
SyntaxError: EOL while scanning string literal

Root Cause

The f-string at line 217 is incorrectly formatted with a line break inside the string literal, which is not supported in Python ≤3.11.

Proposed Fix

Current (broken) code:

command = f"SR{cell_or_tag}{formatted_row}{row_offset_or_col_offset} {
                col_offset_or_high} {high_or_wide} {wide_or_angle} {angle_or_curve} {curve}"

Fixed code:

command = f"SR{cell_or_tag}{formatted_row}{row_offset_or_col_offset} {col_offset_or_high} {high_or_wide} {wide_or_angle} {angle_or_curve} {curve}"

Environment

  • Python Version: 3.9 (affects Python ≤3.11)
  • Package: CognexNativePy
  • Platform: Any

Impact

This syntax error prevents the entire library from being imported on Python versions ≤3.11, making it unusable for users who haven't upgraded to Python 3.12+.

Request

Please fix this f-string formatting issue to ensure compatibility with older Python versions that are still widely used in production environments.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions