◐ Shell
reader mode source ↗
Skip to content

gh-104306: Fix incorrect comment handling in the netrc module, minor refactor#104511

Open
sleiderr wants to merge 19 commits into
python:mainfrom
sleiderr:gh-104306-netrc-comments
Open

gh-104306: Fix incorrect comment handling in the netrc module, minor refactor#104511
sleiderr wants to merge 19 commits into
python:mainfrom
sleiderr:gh-104306-netrc-comments

Conversation

@sleiderr

Copy link
Copy Markdown

@bedevere-bot

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@ghost

ghost commented May 15, 2023

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-bot

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@ssbarnea

ssbarnea commented Jan 4, 2025

Copy link
Copy Markdown
Contributor

Any chance we can revive this? I already spend few hours trying to identify why I was getting 404 errors from github.com, just to discover that it was a commented line in my ~/.netrc, one that was ignored correctly by curl.

@webknjaz

webknjaz commented Jan 6, 2025

Copy link
Copy Markdown
Member

@sleiderr the CI is failing with this PR. Here I've extracted the relevant part of the log from one of the jobs:

1 test failed:
    test_netrc

435 tests OK.

0:12:34 load avg: 5.15 Re-running 1 failed tests in verbose mode in subprocesses
0:12:34 load avg: 5.15 Run 1 test in parallel using 1 worker process (timeout: 10 min, worker timeout: 15 min)
0:12:34 load avg: 5.15 [1/1/1] test_netrc failed (uncaught exception)
Re-running test_netrc in verbose mode
test test_netrc crashed -- Traceback (most recent call last):
  File "D:\a\cpython\cpython\Lib\test\libregrtest\single.py", line 184, in _runtest_env_changed_exc
    _load_run_test(result, runtests)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "D:\a\cpython\cpython\Lib\test\libregrtest\single.py", line 129, in _load_run_test
    test_mod = importlib.import_module(module_name)
  File "D:\a\cpython\cpython\Lib\importlib\__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1386, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1359, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1330, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 756, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "D:\a\cpython\cpython\Lib\test\test_netrc.py", line 6, in <module>
    from test.support import os_helper, run_unittest
ImportError: cannot import name 'run_unittest' from 'test.support' (D:\a\cpython\cpython\Lib\test\support\__init__.py)
1 test failed again:
    test_netrc

== Tests result: FAILURE then FAILURE ==

(https://github.com/python/cpython/actions/runs/12611674426/job/35147581981?pr=104511#step:6:631)

@webknjaz webknjaz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hide comment

I think that dropping the unrelated changes may fix #104511 (comment).

sleiderr and others added 2 commits January 6, 2025 21:37
Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <wk.cvs.github@sydorenko.org.ua>
Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <wk.cvs.github@sydorenko.org.ua>
Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <wk.cvs.github@sydorenko.org.ua>
@webknjaz

webknjaz commented Jan 6, 2025

Copy link
Copy Markdown
Member
0:00:07 load avg: 9.38 [ 59/482] test_netrc passed

@sleiderr

sleiderr commented Jan 7, 2025

Copy link
Copy Markdown
Author

Hi @webknjaz - thanks for reviewing this pull request.

I agree that most of the changes were not relevant to the actual bug fix and were more confusing than anything else (even for myself, one year later).

I've reverted to the upstream version of the module, and fixed the bug in (hopefully) a clearer manner.
Trailing new lines were messing up a check that I assume was supposed to determine whether a token was the the last one on a line, to then ensure that we do not skip line twice when parsing comment. But the way this check is implemented (checking if the current line number increased after calling the lever) is not quite correct, especially with extra blank lines that increase the current line number, but do not necessarily mean that the token was the last on its line.

Removing extra new lines before storing the line count fixes that issue, I've added a few test cases based on the original bug report.

@webknjaz

Copy link
Copy Markdown
Member

@sleiderr would you improve the change note with now this affects the end-users in practice? No low-level details, just relatable high-level effects.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 13, 2026
@avalentino

Copy link
Copy Markdown

For what it matters I would love to see this PR merged

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants