From 0a29cdd6529e19de7427ac2f107cf4e807c0fa32 Mon Sep 17 00:00:00 2001 From: Elmer de Looff Date: Wed, 4 Jun 2025 19:12:37 +0200 Subject: [PATCH 1/2] Excludes 'env' directory from linting. --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index bfbeb56..85f4df4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,6 +9,7 @@ exclude = ''' \.git | .tox | build + | env )/ ''' @@ -17,4 +18,5 @@ exclude = ''' [tool.isort] profile = "black" src_paths = ["src", "tests"] +skip_glob = "env/*" known_first_party = "venusian" From b5d28f347810054a11f472cf49b79237a1b3a057 Mon Sep 17 00:00:00 2001 From: Elmer de Looff Date: Wed, 4 Jun 2025 19:13:31 +0200 Subject: [PATCH 2/2] Fixes ValueError getting swallowed in callback execution during scan. --- src/venusian/__init__.py | 23 ++++++++++--------- .../fixtures/callback_valueerror/__init__.py | 14 +++++++++++ tests/test_venusian.py | 9 ++++++++ 3 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 tests/fixtures/callback_valueerror/__init__.py diff --git a/src/venusian/__init__.py b/src/venusian/__init__.py index 5fd08ce..a4d9945 100644 --- a/src/venusian/__init__.py +++ b/src/venusian/__init__.py @@ -175,17 +175,18 @@ def invoke(mod_name, name, ob): return for category in category_keys: callbacks = attached_categories.get(category, []) - try: - # Metaclasses might trick us by reaching this far and then - # fail with too little values to unpack. - for callback, cb_mod_name, liftid, scope in callbacks: - if cb_mod_name != mod_name: - # avoid processing objects that were imported into - # this module but were not actually defined there - continue - callback(self, name, ob) - except ValueError: # pragma: nocover - continue + for cb_tuple in callbacks: + try: + # Metaclasses might trick us by reaching this far and then + # fail with too little values to unpack. + callback, cb_mod_name, liftid, scope = cb_tuple + except ValueError: # pragma: nocover + continue + if cb_mod_name != mod_name: + # avoid processing objects that were imported into + # this module but were not actually defined there + continue + callback(self, name, ob) for name, ob in getmembers(package): # whether it's a module or a package, we need to scan its diff --git a/tests/fixtures/callback_valueerror/__init__.py b/tests/fixtures/callback_valueerror/__init__.py new file mode 100644 index 0000000..968efdf --- /dev/null +++ b/tests/fixtures/callback_valueerror/__init__.py @@ -0,0 +1,14 @@ +import venusian + + +def decorator(wrapped): + def callback(context, name, ob): + raise ValueError + + venusian.attach(wrapped, callback) + return wrapped + + +@decorator +def function(request): # pragma: no cover + return request diff --git a/tests/test_venusian.py b/tests/test_venusian.py index d09b0d5..373437c 100644 --- a/tests/test_venusian.py +++ b/tests/test_venusian.py @@ -426,6 +426,15 @@ def ignore_child(name): self.assertEqual(test.registrations[0]["ob"], func1) self.assertEqual(test.registrations[0]["function"], True) + def test_valueerror_during_scan_in_callback(self): + from tests.fixtures import callback_valueerror + + test = _Test() + scanner = self._makeOne(test=test) + # without a custom onerror, scan will propagate the importerror from + # will_cause_import_error + self.assertRaises(ValueError, scanner.scan, callback_valueerror) + def test_ignore_by_full_dotted_name(self): from tests.fixtures import one