Message ID | 20241016091212.2263153-1-jwakely@redhat.com |
---|---|
State | New |
Headers | show |
Series | [committed] libstdc++: Fix Python deprecation warning in printers.py | expand |
>>>>> "Jonathan" == Jonathan Wakely <jwakely@redhat.com> writes:
Jonathan> Using a keyword argument for count only became possible with Python 3.1
Jonathan> so introduce a new function to do the substitution.
gdb docs are inconsistent on this, but at least one spot says that the
minimum supported Python version is 3.2. Plus, I know we agreed that
the minimum should be 3.4, and I'll be sending a patch to this effect
soon.
Anyway, I think it would be reasonably safe to just assume 3.1 if you
want to do that.
Tom
On Wed, 16 Oct 2024 at 16:58, Tom Tromey <tom@tromey.com> wrote: > > >>>>> "Jonathan" == Jonathan Wakely <jwakely@redhat.com> writes: > > Jonathan> Using a keyword argument for count only became possible with Python 3.1 > Jonathan> so introduce a new function to do the substitution. > > gdb docs are inconsistent on this, but at least one spot says that the > minimum supported Python version is 3.2. Plus, I know we agreed that > the minimum should be 3.4, and I'll be sending a patch to this effect > soon. > > Anyway, I think it would be reasonably safe to just assume 3.1 if you > want to do that. We still have a few places in the printers.py file that check for Python 3 vs Python 2, so I did so here too. For the Python 3 case, I'm assuming 3.1 or later, because I can imagine some people might be stuck on Python 2 for some reason (and also unable to build GDB with Python 3? ... maybe unlikely) but nobody should be stuck on 3.0 and unable to replace that with 3.12 or so. So the condition is Python 2x, or Python 3.1+, and Python 3.0 is unsupported. If we no longer care about Python 2 there are a few places in that file we could clean up.
>>>>> "Jonathan" == Jonathan Wakely <jwakely@redhat.com> writes:
Jonathan> also unable to build GDB with Python 3? ... maybe unlikely) but nobody
Jonathan> should be stuck on 3.0 and unable to replace that with 3.12 or so.
gdb has one user (maybe more, but I doubt it) on Windows XP where the
latest available version is 3.4.
Jonathan> If we no longer care about Python 2 there are a few places in that
Jonathan> file we could clean up.
Python 2 support was dropped from gdb in December 2021. Unfortunately
this wasn't mentioned in gdb/NEWS, but according to git this seems to
have happened in gdb 13. So I think it's safe to fix this up.
Tom
diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index 92104937862..d05b79762fd 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -220,6 +220,16 @@ def strip_versioned_namespace(typename): return typename.replace(_versioned_namespace, '') +def strip_fundts_namespace(typ): + """Remove "fundamentals_vN" inline namespace from qualified type name.""" + pattern = r'^std::experimental::fundamentals_v\d::' + repl = 'std::experimental::' + if sys.version_info[0] == 2: + return re.sub(pattern, repl, typ, 1) + else: # Technically this needs Python 3.1 but nobody should be using 3.0 + return re.sub(pattern, repl, typ, count=1) + + def strip_inline_namespaces(type_str): """Remove known inline namespaces from the canonical name of a type.""" type_str = strip_versioned_namespace(type_str) @@ -1355,8 +1365,7 @@ class StdExpAnyPrinter(SingleObjContainerPrinter): def __init__(self, typename, val): self._typename = strip_versioned_namespace(typename) - self._typename = re.sub(r'^std::experimental::fundamentals_v\d::', - 'std::experimental::', self._typename, 1) + self._typename = strip_fundts_namespace(self._typename) self._val = val self._contained_type = None contained_value = None @@ -1449,10 +1458,8 @@ class StdExpOptionalPrinter(SingleObjContainerPrinter): """Print a std::optional or std::experimental::optional.""" def __init__(self, typename, val): - typename = strip_versioned_namespace(typename) - self._typename = re.sub( - r'^std::(experimental::|)(fundamentals_v\d::|)(.*)', - r'std::\1\3', typename, 1) + self._typename = strip_versioned_namespace(typename) + self._typename = strip_fundts_namespace(self._typename) payload = val['_M_payload'] if self._typename.startswith('std::experimental'): engaged = val['_M_engaged']