Skip to content

Conversation

@sleiderr
Copy link

@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

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

@ghost
Copy link

ghost commented May 15, 2023

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

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

@ssbarnea
Copy link
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.

@@ -0,0 +1 @@
Fix incorrect comment parsing in the :mod:`netrc` module.
Copy link
Member

Choose a reason for hiding this comment

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

Could you expand on this and include context that would give an arbitrary changelog reader an idea of how the change might impact them?

('anonymous', '', 'pass'))


deftest_main():
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed?

@webknjaz
Copy link
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_modulereturn _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)

importsys
importtextwrap
importunittest
fromtest.supportimportos_helper, run_unittest
Copy link
Member

Choose a reason for hiding this comment

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

This causes a ImportError: cannot import name 'run_unittest' from 'test.support' (#104511 (comment)).

Copy link
Member

@webknjazwebknjaz left a comment

Choose a reason for hiding this comment

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

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

sleiderrand 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
Copy link
Member

0:00:07 load avg: 9.38 [ 59/482] test_netrc passed

forlineinself.macros[macro]:
rep+=line
rep+="\n"
returnrep
Copy link
Member

Choose a reason for hiding this comment

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

Revert deleting the CLI entry point logic:

Suggested change
returnrep
returnrep
if__name__=='__main__':
print(netrc())

Lib/netrc.py Outdated
Comment on lines 121 to 122
raiseNetrcParseError(
"missing %r name"%tt, file, lexer.lineno)
Copy link
Member

Choose a reason for hiding this comment

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

looks like an irrelevant formatting change

Suggested change
raiseNetrcParseError(
"missing %r name"%tt, file, lexer.lineno)
raiseNetrcParseError("missing %r name"%tt, file, lexer.lineno)

Lib/netrc.py Outdated
iflexer.lineno==saved_linenoandlen(tt) ==1:
# For top level tokens, we skip line if the # is followed
# by a space / newline. Otherwise, we only skip the token.
iftt=='#'andnotlexer.dontskip:
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if I understand why the entirety of t is being compared to a '#'. Is this semantically “the entire token consists of just #”?
This could be

Suggested change
iftt=='#'andnotlexer.dontskip:
iflen(tt)==1andnotlexer.dontskip:

but then, why does it matter whether it's # thing vs #thing? Typically, comment parsers just disregard whatever's after the hash and don't interpret that in any way…

Lib/netrc.py Outdated
ifchinself.whitespaceandnotenquoted:
iftoken=="":
continue
ifch=='\n':
Copy link
Member

Choose a reason for hiding this comment

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

What about \r? \r\n?

Lib/netrc.py Outdated
forchinfiter:
ifchinself.whitespace:
enquoted=False
whilech:=self._read_char():
Copy link
Member

Choose a reason for hiding this comment

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

Was this refactoring necessary to fix the bug? It's rather difficult to read the diff with so many lines reshuffled. If I were to guess, this might be the reason people are postponing doing reviews on this PR.

Lib/netrc.py Outdated
Comment on lines 5 to 6
importos
importstat
Copy link
Member

Choose a reason for hiding this comment

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

Let's undo formatting to make sure only relevant changes are visible in the diff.

Suggested change
importos
importstat
importos, stat

Lib/netrc.py Outdated
returnself.hosts['default']
else:
returnNone
returnself.hosts.get(host, self.hosts.get('default'))
Copy link
Member

Choose a reason for hiding this comment

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

I have a feeling that this might not be relevant to the fix and would be better in a separate refactoring PR.

@sleiderr
Copy link
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
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.

Sign up for freeto 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.

5 participants

@sleiderr@bedevere-bot@ssbarnea@webknjaz@arhadthedev