diff --git a/changelog.d/+invalid-escape-sequences.fixed b/changelog.d/+invalid-escape-sequences.fixed new file mode 100644 index 00000000..f89789c4 --- /dev/null +++ b/changelog.d/+invalid-escape-sequences.fixed @@ -0,0 +1 @@ +Fix `SyntaxWarning: invalid escape sequence '\*'` emitted when `coreai_opt.quantization.config` is compiled on Python 3.12+ (and a `SyntaxError` under `python -W error`). diff --git a/pyproject.toml b/pyproject.toml index 23eb9e2b..f79a5734 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -263,6 +263,7 @@ select = [ "RUF100", # remove unused noqa pragmas "TC004", # catch runtime imports in TYPE_CHECKING blocks "UP", # apply pyupgrade modernization rules + "W605", # invalid escape sequences (SyntaxWarning since Python 3.12) ] ignore = [ "ANN401", # allow type `Any`. diff --git a/src/coreai_opt/quantization/config/quantization_config.py b/src/coreai_opt/quantization/config/quantization_config.py index e63858c3..0d434fcc 100644 --- a/src/coreai_opt/quantization/config/quantization_config.py +++ b/src/coreai_opt/quantization/config/quantization_config.py @@ -169,7 +169,7 @@ def __init__(self, execution_mode: object) -> None: class OpQuantizerConfig(OpCompressionConfig[QuantizationSpec]): - """ + r""" Configuration class for quantization at the operation level. This class specifies quantization settings for inputs, outputs, and state @@ -271,7 +271,7 @@ def get_default_state_spec(cls) -> dict[str, QuantizationSpec | None]: @final class ModuleQuantizerConfig(ModuleCompressionConfig[OpQuantizerConfig, QuantizationSpec]): - """ + r""" Configuration class for quantization at the module level. This class manages quantization settings for an entire module, including: diff --git a/tests/quantization/test_annotation_pattern_registry.py b/tests/quantization/test_annotation_pattern_registry.py index 66b006a8..c1906dcf 100644 --- a/tests/quantization/test_annotation_pattern_registry.py +++ b/tests/quantization/test_annotation_pattern_registry.py @@ -3414,7 +3414,7 @@ def test_none_configs(self, config, expected): QuantizerConfig( global_config=None, module_name_configs={ - "inner_module\.linear_out.*": ModuleQuantizerConfig( + r"inner_module\.linear_out.*": ModuleQuantizerConfig( op_state_spec=None, module_state_spec={"weight": default_weight_quantization_spec()}, ) @@ -3508,7 +3508,7 @@ def test_module_level_setting_precedence(self): ) }, module_name_configs={ - "inner_module\.linear_out1": ModuleQuantizerConfig( + r"inner_module\.linear_out1": ModuleQuantizerConfig( op_input_spec=None, op_output_spec=None, op_state_spec=None, @@ -4156,7 +4156,7 @@ def test_shared_param_precedence( ) }, ), - "Only integer indices or '\*' are supported", + r"Only integer indices or '\*' are supported", ), ( QuantizerConfig( @@ -4167,7 +4167,7 @@ def test_shared_param_precedence( ) }, ), - "Only integer indices or '\*' are supported", + r"Only integer indices or '\*' are supported", ), ( QuantizerConfig( diff --git a/tests/test_source_compiles.py b/tests/test_source_compiles.py new file mode 100644 index 00000000..09cbe5a4 --- /dev/null +++ b/tests/test_source_compiles.py @@ -0,0 +1,25 @@ +# Copyright 2026 Apple Inc. +# +# Use of this source code is governed by a BSD-3-Clause license that can +# be found in the LICENSE file or at https://opensource.org/licenses/BSD-3-Clause + +"""Check that the package source compiles without warnings.""" + +import warnings +from pathlib import Path + +import pytest + +import coreai_opt + +_SRC_ROOT = Path(coreai_opt.__file__).parent +_SOURCE_FILES = sorted(_SRC_ROOT.rglob("*.py")) + + +@pytest.mark.parametrize("path", _SOURCE_FILES, ids=lambda p: str(p.relative_to(_SRC_ROOT.parent))) +def test_source_compiles_without_warnings(path: Path) -> None: + # Things like invalid escape sequences only warn at compile time, and the + # warning is lost once a .pyc is cached, so compile from source directly. + with warnings.catch_warnings(): + warnings.simplefilter("error") + compile(path.read_text(encoding="utf-8"), str(path), "exec")