[go: up one dir, main page]

Avoid "unsupported format character ')'" on Python 3.14

What does the merge request do?

Escape the literal % in argument help.

Implementation notes

On Python 3.14.0a3:

__________________________ InxTestCase.test_inx_files __________________________

self = ArgumentParser(prog='pytest', usage=None, description='Snap objects to pixels', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)
action = _StoreAction(option_strings=['-g', '--max_gradient'], dest='max_gradient', nargs=None, const=None, default=0.5, type=<... 'float'>, choices=None, required=False, help='Maximum slope to consider straight (%)', metavar=None, deprecated=False)

    def _check_help(self, action):
        if action.help and hasattr(self, "_get_formatter"):
            formatter = self._get_formatter()
            try:
>               formatter._expand_help(action)

/usr/lib64/python3.14/argparse.py:1665: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <argparse.HelpFormatter object at 0x7f9103c64890>
action = _StoreAction(option_strings=['-g', '--max_gradient'], dest='max_gradient', nargs=None, const=None, default=0.5, type=<... 'float'>, choices=None, required=False, help='Maximum slope to consider straight (%)', metavar=None, deprecated=False)

    def _expand_help(self, action):
        help_string = self._get_help_string(action)
        if '%' not in help_string:
            return help_string
        params = dict(vars(action), prog=self._prog)
        for name in list(params):
            value = params[name]
            if value is SUPPRESS:
                del params[name]
            elif hasattr(value, '__name__'):
                params[name] = value.__name__
        if params.get('choices') is not None:
            params['choices'] = ', '.join(map(str, params['choices']))
>       return help_string % params
E       ValueError: unsupported format character ')' (0x29) at index 37

/usr/lib64/python3.14/argparse.py:604: ValueError

The above exception was the direct cause of the following exception:

self = <tests.test_inkex_inx.InxTestCase testMethod=test_inx_files>

    def test_inx_files(self):
        """Get all inx files and test each of them"""
        if not PY3:
            self.skipTest("No INX testing in python2")
            return
        for inx_file in glob(os.path.join(self._testdir(), "..", "*.inx")):
            with self.subTest(inx_file=inx_file):
                self.assertInxSchemaValid(inx_file)
>               self.assertInxIsGood(inx_file)

tests/test_inkex_inx.py:159: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
inkex/tester/inx.py:52: in assertInxIsGood
    self.assertParams(inx, cls)
inkex/tester/inx.py:60: in assertParams
    args = dict(self.introspect_arg_parser(cls().arg_parser))
inkex/base.py:475: in __init__
    super().__init__()
inkex/base.py:91: in __init__
    self.add_arguments(self.arg_parser)
pixelsnap.py:130: in add_arguments
    pars.add_argument(
/usr/lib64/python3.14/argparse.py:1479: in add_argument
    self._check_help(action)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = ArgumentParser(prog='pytest', usage=None, description='Snap objects to pixels', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)
action = _StoreAction(option_strings=['-g', '--max_gradient'], dest='max_gradient', nargs=None, const=None, default=0.5, type=<... 'float'>, choices=None, required=False, help='Maximum slope to consider straight (%)', metavar=None, deprecated=False)

    def _check_help(self, action):
        if action.help and hasattr(self, "_get_formatter"):
            formatter = self._get_formatter()
            try:
                formatter._expand_help(action)
            except (ValueError, TypeError, KeyError) as exc:
>               raise ValueError('badly formed help string') from exc
E               ValueError: badly formed help string

/usr/lib64/python3.14/argparse.py:1667: ValueError

This makes that problem go away.

Summary for release notes

Fix a problem with argument paring on Python 3.14.

Checklist

  • Add unit tests (if applicable)
  • Changes to inkex/ are well documented
  • Clean merge request history

Merge request reports

Loading