Skip to content

Avoid printing autoimport syntax errors - #847

Merged
lieryan merged 2 commits into
python-rope:masterfrom
yangfan-yf-yf:fix/autoimport-invalid-source-output
Aug 16, 2026
Merged

Avoid printing autoimport syntax errors#847
lieryan merged 2 commits into
python-rope:masterfrom
yangfan-yf-yf:fix/autoimport-invalid-source-output

Conversation

@yangfan-yf-yf

Copy link
Copy Markdown
Contributor

Summary

When autoimport scans an invalid source file, get_names_from_file() prints the SyntaxError to standard output. On Windows consoles using GBK, a syntax error containing an unencodable character can raise UnicodeEncodeError in the worker process and interrupt cache generation.

This switches the diagnostic to the existing module logger at debug level. Invalid files continue to be skipped, without writing to standard output.

Validation

  • Added a regression test for an invalid source file containing ; it verifies the file is skipped, the diagnostic is logged, and standard output stays empty.
  • python -m pytest -q ropetest/contrib/autoimport/parsetest.py — 4 passed
  • python -m pytest -q --deselect=ropetest/contrib/autoimporttest.py::AutoImportTest::test_generate_full_cache --deselect=ropetest/contrib/autoimporttest.py::AutoImportTest::test_skipping_directories_not_accessible_because_of_permission_error — 2090 passed, 8 skipped, 5 xfailed
  • The two deselected autoimport tests fail unchanged on the Windows baseline because of console encoding and permission-fixture behavior.
  • python -m pre_commit run --files rope/contrib/autoimport/parse.py ropetest/contrib/autoimport/parsetest.py

@yangfan-yf-yf
yangfan-yf-yf marked this pull request as ready for review July 23, 2026 15:35
@lieryan lieryan added this to the 1.15.0 milestone Aug 16, 2026
@lieryan

lieryan commented Aug 16, 2026

Copy link
Copy Markdown
Member

Thanks for fixing this issue, the fix looks good to me @yangfan-yf-yf

@allcontributors please add @yangfan-yf-yf for code contribution

@allcontributors

Copy link
Copy Markdown
Contributor

@lieryan

I've put up a pull request to add @yangfan-yf-yf! 🎉

@lieryan
lieryan merged commit 1fed35f into python-rope:master Aug 16, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants