Skip to content

Commit 06f3bcc

Browse files
committed
Tolerate Python 3.12 'did you mean _return_value'
1 parent ac9e21c commit 06f3bcc

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ pip-wheel-metadata
1818
/.dmypy.json
1919
TODO.txt
2020
/venv
21+
/.venv

tests/test_hydra.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,8 +1287,18 @@ def test_app_with_error_exception_sanitized(tmpdir: Any, monkeypatch: Any) -> No
12871287
f"hydra.sweep.dir={tmpdir}",
12881288
"hydra.job.chdir=True",
12891289
]
1290+
1291+
# Python 3.12 introduced enhanced error messages that suggest similar attribute
1292+
# names for AttributeError. Unfortunately, it suggests private attributes like
1293+
# '_return_value'
1294+
# Python 3.13+ fixes this by not suggesting private attributes.
1295+
if sys.version_info >= (3, 12) and sys.version_info < (3, 13):
1296+
suggestion_suffix = r". Did you mean: '_return_value'\?"
1297+
else:
1298+
suggestion_suffix = r""
1299+
12901300
expected_regex = dedent(
1291-
r"""
1301+
rf"""
12921302
Error executing job with overrides: \[\]
12931303
Traceback \(most recent call last\):
12941304
File ".*my_app\.py", line 13, in my_app
@@ -1298,7 +1308,7 @@ def test_app_with_error_exception_sanitized(tmpdir: Any, monkeypatch: Any) -> No
12981308
\^+)?
12991309
omegaconf\.errors\.ConfigAttributeError: Key 'foo' is not in struct
13001310
full_key: foo
1301-
object_type=dict
1311+
object_type=dict{suggestion_suffix}
13021312
13031313
Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace\.
13041314
"""

0 commit comments

Comments
 (0)