Repository navigation
Closed
Labels
3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
| BPO | 34132 |
|---|---|
| Nosy | @smontanaro, @zhangyangyu, @bbayles, @tirkarthi |
| PRs | |
| Files |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = None
closed_at = None
created_at = <Date 2018-07-16.23:13:33.685>
labels = ['3.7', '3.8', 'type-bug', 'library']
title = 'Obscure netrc parser "bug"'
updated_at = <Date 2018-07-21.00:54:36.328>
user = 'https://github.com/smontanaro'bugs.python.org fields:
activity = <Date 2018-07-21.00:54:36.328>
actor = 'bbayles'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2018-07-16.23:13:33.685>
creator = 'skip.montanaro'
dependencies = []
files = ['47696', '47697', '47699']
hgrepos = []
issue_num = 34132
keywords = ['patch']
message_count = 4.0
messages = ['321779', '321810', '321975', '322053']
nosy_count = 4.0
nosy_names = ['skip.montanaro', 'xiang.zhang', 'bbayles', 'xtreak']
pr_nums = ['8320', '8360']
priority = 'normal'
resolution = None
stage = 'patch review'
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue34132'
versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']Metadata
Metadata
Assignees
Labels
3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
smontanaro commentedon Jul 16, 2018
Not sure I can really call this a bug, however there is a behavioral change between 2.7 and at least 3.6 and 3.7 (probably earlier versions of the 3.x series as well). There is no spec for .netrc files that I can find, certainly nothing which mentions comment or blank lines. Still, Python's netrc file parser seems happy with both.
However, in 3.x a blank line followed immediately by a comment line containing actual comment text causes the parser to raise a parse error. I've attached two netrc files, netrc-comment-blank, and netrc-blank-comment, identical save for the ordering of a blank line and a comment line. Here's what a 2.7.14 session looks like:
Here's 3.7.0:
tirkarthi commentedon Jul 17, 2018
This seems to have been introduced with commit : 1df0f21 before which it was working fine.
Testing shows the error from 1df0f21 and above. I have checked out only versions of Lib/netrc.py and I think this doesn't require a rebuild of Python.
➜ cpython git:(master) $ git log --oneline --format="%h" Lib/netrc.py > commits.txt # Get all commits to test the changes
➜ cpython git:(master) ✗ ./python netrc_foo_tester.py
netrc_foo_tester.py is attached with the message which basically does the below using Python for every commit. netrc_foo.py contains the actual test of parsing two files.
➜ cpython git:(master) ✗ ./python
Python 3.8.0a0 (heads/master:35c0809, Jul 16 2018, 10:29:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
➜ cpython git:(master) ✗ cat netrc_foo.py
import netrc
I hope the above approach is correct.
Thanks
bbayles commentedon Jul 20, 2018
I took a shot at this, but closed my PR when I found that it introduced a different regression.
After playing with it for a bit, I think that this commit [1] is a bit problematic because it uses lexer.instream.readline(), which can make the line number in lexer.lineno incorrect.
I may take another look if I have time, but someone else is free to tackle this.
[1] 1df0f21#diff-e6896f6d68ca3fd8094a933533f8b2ed
bbayles commentedon Jul 21, 2018
I realized that the Python 2 solution was adapt-able after all; I've re-submitted as GitHub PR 8360.
#8360
diegogimenez04 commentedon Jun 9, 2026
Hello everyone. Is this still an issue in newer versions? If not, I suggest closing it.
hugovk commentedon Oct 25, 2026
Likely duplicate of #79089, fixed by #26330.