On Wed, 27 Sept 2023 at 16:37, Tom Tromey <tro...@adacore.com> wrote: > > >>>>> Jonathan Wakely via Gcc-patches <gcc-patches@gcc.gnu.org> writes: > > Replying to a quite old email... > > I ran a Python linter on the libstdc++ pretty-printers. > > I have fixes for most of the issues that are worth fixing (I didn't > bother with line lengths -- FWIW in gdb we just run 'black' and don't > worry about these details),
I used autopep8 and committed the result as e08559271b2d797f658579ac8610dbf5e58bcfd8 so the line lengths should be OK now. > but the patch I'm replying to had a problem > that I didn't know how to fix: > > > +class StdChronoTimeZoneRulePrinter: > [...] > > + if kind == 0: # DayOfMonth > > + start = '{} {}{}'.format(month, ordinal_day) > > flake8 points out that this call to format has three placeholders but > only two arguments. Oops, I think it was originally written like this: '{} {}{}'.format(month, day, suffixes.get(day, 'th')) but then I refactored it to: ordinal_day = '{}{}'.format(day, suffixes.get(day, 'th')) if kind == 0: # DayOfMonth start = '{} {}{}'.format(month, ordinal_day) So the fix is to just change the string to '{} {}' which I've pushed as 1fab05a885a308c19cf42b72fd36805ddf27fdc8 now (also attached). These printers are for implementation details internal to the library, which are never exposed to users. I added them because they made it much easier to debug the implementation when stepping through library functions, but that means there are no tests for them. Thanks for finding this!
commit 1fab05a885a308c19cf42b72fd36805ddf27fdc8 Author: Jonathan Wakely <jwak...@redhat.com> Date: Wed Sep 27 17:03:51 2023 libstdc++: Fix format string in StdChronoTimeZoneRulePrinter libstdc++-v3/ChangeLog: * python/libstdcxx/v6/printers.py (StdChronoTimeZoneRulePrinter): Fix incorrect number of replacement fields. diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index c0056de2565..d60c8003a63 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -2215,7 +2215,7 @@ class StdChronoTimeZoneRulePrinter: day = on['day_of_month'] ordinal_day = '{}{}'.format(day, suffixes.get(day, 'th')) if kind == 0: # DayOfMonth - start = '{} {}{}'.format(month, ordinal_day) + start = '{} {}'.format(month, ordinal_day) else: weekday = weekdays[on['day_of_week']] if kind == 1: # LastWeekDay