From eb781513c8380a7ec39bd243841f71458b2fa165 Mon Sep 17 00:00:00 2001 From: Jonathan Neuhauser Date: Sat, 24 May 2025 20:59:42 +0200 Subject: [PATCH] Avoid namespace pollution from inkex.colors by importing selectively --- inkex/__init__.py | 3 ++- tests/test_inkex_colors.py | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/inkex/__init__.py b/inkex/__init__.py index 1e0d553b..6fe3931c 100644 --- a/inkex/__init__.py +++ b/inkex/__init__.py @@ -12,7 +12,8 @@ from .extensions import * from .utils import AbortExtension, DependencyError, Boolean, errormsg from .styles import * from .paths import Path, CubicSuperPath # Path commands are not exported -from .colors import * +from .colors import Color, ColorError, ColorIdError, is_color +from .colors.spaces import * from .transforms import * from .elements import * diff --git a/tests/test_inkex_colors.py b/tests/test_inkex_colors.py index 3d0bc09e..884d3bbb 100644 --- a/tests/test_inkex_colors.py +++ b/tests/test_inkex_colors.py @@ -101,3 +101,10 @@ class ColorTest(TestCase): # Same assumption, but now it's 1.0-0.0 so 0.5 is expected result = Color("#000000").interpolate(white, 0.5) self.assertEqual(result.alpha, 0.5) + + def test_namespace_pollution(self): + """Ensure that inkex.utils does not point to inkex.colors.utils""" + import inkex.utils + + assert not hasattr(inkex.utils, "is_color") + assert not inkex.utils == inkex.colors.utils -- GitLab