This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author nabelekt
Recipients eric.smith, nabelekt, paul.j3, rhettinger
Date 2020-12-19.19:50:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1608407455.09.0.507401847478.issue42677@roundup.psfhosted.org>
In-reply-to
Content
While overloading convert_arg_line_to_args may work, I think that @file reading is kind of the odd ball out in not recognizing '#' as the beginning of a comment.

Besides, I'm not sure that overloading just convert_arg_line_to_args is sufficient. Here is what I have:


import argparse
import re


class ArgumentParserCustom(argparse.ArgumentParser):
    
    def convert_arg_line_to_args(self, arg_line):
    
        if re.match(r'(\s+)?#', arg_line):  # Look for any number of whitespace characters up to a `#` character
            return ['']
        else:
            return [arg_line]


If I return [''], I get:
  "error: unrecognized arguments:".

If I return [None], I get:
  File "C:\Users\tnabelek\AppData\Local\Programs\Python\Python38-32\lib\argparse.py", line 1771, in parse_args
    self.error(msg % ' '.join(argv))
TypeError: sequence item 0: expected str instance, NoneType found


Is there a better solution?
History
Date User Action Args
2020-12-19 19:50:55nabelektsetrecipients: + nabelekt, rhettinger, eric.smith, paul.j3
2020-12-19 19:50:55nabelektsetmessageid: <1608407455.09.0.507401847478.issue42677@roundup.psfhosted.org>
2020-12-19 19:50:55nabelektlinkissue42677 messages
2020-12-19 19:50:54nabelektcreate