Skip to content

Avoid printing autoimport syntax errors#847

Open
yangfan-yf-yf wants to merge 1 commit into
python-rope:masterfrom
yangfan-yf-yf:fix/autoimport-invalid-source-output
Open

Avoid printing autoimport syntax errors#847
yangfan-yf-yf wants to merge 1 commit into
python-rope:masterfrom
yangfan-yf-yf:fix/autoimport-invalid-source-output

Conversation

@yangfan-yf-yf

Copy link
Copy Markdown

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
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.

1 participant