Merge "Fix compatibility with Python 3.10, 3.9.11"

This commit is contained in:
Zuul 2022-10-05 11:56:39 +00:00 committed by Gerrit Code Review
commit ae36c47165
1 changed files with 19 additions and 11 deletions

View File

@ -61,17 +61,25 @@ class Extension(object):
@property
def extras(self):
"""The 'extras' settings for the plugin."""
# NOTE: The underlying package returns re.Match objects for
# some reason. Translate those to the matched strings, which
# seem more useful.
return [
# Python 3.6 returns _sre.SRE_Match objects. Later
# versions of python return re.Match objects. Both types
# have a 'string' attribute containing the text that
# matched the pattern.
getattr(e, 'string', e)
for e in self.entry_point.extras
]
# NOTE: The underlying package returned re.Match objects until this was
# fixed in importlib-metadata 4.11.3. This was fixed in Python 3.10 and
# backported to Python 3.9.11. For older versions without this fix,
# translate the re.Match objects to the matched strings, which seem
# more useful.
extras = []
for extra in self.entry_point.extras:
if isinstance(extra, str):
# We were previously returning the whole string including
# backets. We need to continue doing so to preserve API
# compatibility.
extras.append(f'[{extra}]')
else:
# Python 3.6 returns _sre.SRE_Match objects. Later
# versions of python return re.Match objects. Both types
# have a 'string' attribute containing the text that
# matched the pattern.
extras.append(getattr(extra, 'string', extra))
return extras
@property
def attr(self):