Skip to content

Commit

Permalink
really drop python<=3.7 support (#2391)
Browse files Browse the repository at this point in the history
* really drop python<=3.7 support

Filter all code over `pyupgrade --py38-plus`.

Signed-off-by: Tomasz Kłoczko <kloczek@github.com>

* filter all code over `ruff`

Signed-off-by: Tomasz Kłoczko <kloczek@github.com>

* break long line

Signed-off-by: Tomasz Kłoczko <kloczek@github.com>

---------

Signed-off-by: Tomasz Kłoczko <kloczek@github.com>
  • Loading branch information
kloczek authored Jun 4, 2024
1 parent f1e2fad commit c8856a3
Show file tree
Hide file tree
Showing 35 changed files with 142 additions and 144 deletions.
12 changes: 6 additions & 6 deletions pymdownx/__meta__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __new__(cls, major, minor, micro, release="final", pre=0, post=0, dev=0):
raise ValueError("All version parts except 'release' should be integers.")

if release not in REL_MAP:
raise ValueError("'{}' is not a valid release type.".format(release))
raise ValueError(f"'{release}' is not a valid release type.")

# Ensure valid pre-release (we do not allow implicit pre-releases).
if ".dev-candidate" < release < "final":
Expand Down Expand Up @@ -140,15 +140,15 @@ def _get_canonical(self):

# Assemble major, minor, micro version and append `pre`, `post`, or `dev` if needed..
if self.micro == 0:
ver = "{}.{}".format(self.major, self.minor)
ver = f"{self.major}.{self.minor}"
else:
ver = "{}.{}.{}".format(self.major, self.minor, self.micro)
ver = f"{self.major}.{self.minor}.{self.micro}"
if self._is_pre():
ver += '{}{}'.format(REL_MAP[self.release], self.pre)
ver += f'{REL_MAP[self.release]}{self.pre}'
if self._is_post():
ver += ".post{}".format(self.post)
ver += f".post{self.post}"
if self._is_dev():
ver += ".dev{}".format(self.dev)
ver += f".dev{self.dev}"

return ver

Expand Down
8 changes: 4 additions & 4 deletions pymdownx/arithmatex.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def _fence_mathjax_format(
):
"""Block math formatter."""

text = '<{} class="arithmatex">\n'.format(tag)
text = f'<{tag} class="arithmatex">\n'
if preview:
text += (
'<div class="MathJax_Preview">\n' +
Expand Down Expand Up @@ -205,11 +205,11 @@ def _fence_generic_format(

classes.insert(0, class_name)

id_value = ' id="{}"'.format(id_value) if id_value else ''
id_value = f' id="{id_value}"' if id_value else ''
classes = ' class="{}"'.format(' '.join(classes))
attrs = ' ' + ' '.join('{k}="{v}"'.format(k=k, v=v) for k, v in attrs.items()) if attrs else ''
attrs = ' ' + ' '.join(f'{k}="{v}"' for k, v in attrs.items()) if attrs else ''

return '<{}{}{}{}>{}</{}>'.format(tag, id_value, classes, attrs, wrap.format(math), tag)
return f'<{tag}{id_value}{classes}{attrs}>{wrap.format(math)}</{tag}>'


def arithmatex_fenced_format(**kwargs):
Expand Down
2 changes: 1 addition & 1 deletion pymdownx/b64.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def repl_path(m, base_path):
for b64_ext in file_types:
if ext in b64_ext:
with open(file_name, "rb") as f:
link = " src=\"data:%s;base64,%s\"" % (
link = " src=\"data:{};base64,{}\"".format(
file_types[b64_ext],
base64.b64encode(f.read()).decode('ascii')
)
Expand Down
20 changes: 10 additions & 10 deletions pymdownx/betterem.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@
# ___strong,em___
UNDER_STRONG_EM = r'(_{3})(?!\s)(_{1,2}|[^_]+?)(?<!\s)\1'
# ***strong,em*strong**
STAR_STRONG_EM2 = r'(\*{3})(?![\s\*])%s(?<!\s)\*%s(?<!\s)\*{2}' % (STAR_CONTENT, STAR_CONTENT2)
STAR_STRONG_EM2 = r'(\*{{3}})(?![\s\*]){}(?<!\s)\*{}(?<!\s)\*{{2}}'.format(STAR_CONTENT, STAR_CONTENT2)
# ___strong,em_strong__
UNDER_STRONG_EM2 = r'(_{3})(?![\s_])%s(?<!\s)_%s(?<!\s)_{2}' % (UNDER_CONTENT, UNDER_CONTENT2)
UNDER_STRONG_EM2 = r'(_{{3}})(?![\s_]){}(?<!\s)_{}(?<!\s)_{{2}}'.format(UNDER_CONTENT, UNDER_CONTENT2)
# ***em,strong**em*
STAR_EM_STRONG = r'(\*{3})(?![\s\*])%s(?<!\s)\*{2}%s(?<!\s)\*' % (STAR_CONTENT2, STAR_CONTENT)
STAR_EM_STRONG = r'(\*{{3}})(?![\s\*]){}(?<!\s)\*{{2}}{}(?<!\s)\*'.format(STAR_CONTENT2, STAR_CONTENT)
# **strong*em,strong***
STAR_STRONG_EM3 = r'(\*{2})(?![\s\*])%s\*(?![\s\*])%s(?<!\s)\*{3}' % (STAR_CONTENT, STAR_CONTENT)
STAR_STRONG_EM3 = r'(\*{{2}})(?![\s\*]){}\*(?![\s\*]){}(?<!\s)\*{{3}}'.format(STAR_CONTENT, STAR_CONTENT)
# ___em,strong__em_
UNDER_EM_STRONG = r'(_{3})(?![\s_])%s(?<!\s)_{2}%s(?<!\s)_' % (UNDER_CONTENT2, UNDER_CONTENT)
UNDER_EM_STRONG = r'(_{{3}})(?![\s_]){}(?<!\s)_{{2}}{}(?<!\s)_'.format(UNDER_CONTENT2, UNDER_CONTENT)
# __strong_em,strong___
UNDER_STRONG_EM3 = r'(_{2})(?![\s_])%s_(?![\s_])%s(?<!\s)_{3}' % (UNDER_CONTENT, UNDER_CONTENT)
UNDER_STRONG_EM3 = r'(_{{2}})(?![\s_]){}_(?![\s_]){}(?<!\s)_{{3}}'.format(UNDER_CONTENT, UNDER_CONTENT)
# **strong**
STAR_STRONG = r'(\*{2})(?!\s)%s(?<!\s)\1' % STAR_CONTENT2
# __strong__
Expand All @@ -73,10 +73,10 @@
SMART_UNDER_STRONG_EM = r'(?<!\w)(_{3})(?![\s_])%s(?<!\s)\1(?!\w)' % SMART_UNDER_CONTENT
# ___strong,em_ strong__
SMART_UNDER_STRONG_EM2 = \
r'(?<!\w)(_{3})(?![\s_])%s(?<!\s)_(?!\w)%s(?<!\s)_{2}(?!\w)' % (SMART_UNDER_CONTENT, SMART_UNDER_CONTENT)
r'(?<!\w)(_{{3}})(?![\s_]){}(?<!\s)_(?!\w){}(?<!\s)_{{2}}(?!\w)'.format(SMART_UNDER_CONTENT, SMART_UNDER_CONTENT)
# ___em,strong__ em_
SMART_UNDER_EM_STRONG = \
r'(?<!\w)(_{3})(?![\s_])%s(?<!\s)_{2}(?!\w)%s(?<!\s)_(?!\w)' % (SMART_UNDER_CONTENT, SMART_UNDER_CONTENT)
r'(?<!\w)(_{{3}})(?![\s_]){}(?<!\s)_{{2}}(?!\w){}(?<!\s)_(?!\w)'.format(SMART_UNDER_CONTENT, SMART_UNDER_CONTENT)
# __strong__
SMART_UNDER_STRONG = r'(?<!\w)(_{2})(?![\s_])%s(?<!\s)\1(?!\w)' % SMART_UNDER_CONTENT
# SMART _em_
Expand All @@ -89,12 +89,12 @@
SMART_STAR_STRONG_EM = r'(?:(?<=_)|(?<![\w\*]))(\*{3})(?![\s\*])%s(?<!\s)\1(?:(?=_)|(?![\w\*]))' % SMART_STAR_CONTENT
# ***strong,em* strong**
SMART_STAR_STRONG_EM2 = \
r'(?:(?<=_)|(?<![\w\*]))(\*{3})(?![\s\*])%s(?<!\s)\*(?:(?=_)|(?![\w\*]))%s(?<!\s)\*{2}(?:(?=_)|(?![\w\*]))' % (
r'(?:(?<=_)|(?<![\w\*]))(\*{{3}})(?![\s\*]){}(?<!\s)\*(?:(?=_)|(?![\w\*])){}(?<!\s)\*{{2}}(?:(?=_)|(?![\w\*]))'.format(
SMART_STAR_CONTENT, SMART_STAR_CONTENT
)
# ***em,strong** em*
SMART_STAR_EM_STRONG = \
r'(?:(?<=_)|(?<![\w\*]))(\*{3})(?![\s\*])%s(?<!\s)\*{2}(?:(?=_)|(?![\w\*]))%s(?<!\s)\*(?:(?=_)|(?![\w\*]))' % (
r'(?:(?<=_)|(?<![\w\*]))(\*{{3}})(?![\s\*]){}(?<!\s)\*{{2}}(?:(?=_)|(?![\w\*])){}(?<!\s)\*(?:(?=_)|(?![\w\*]))'.format(
SMART_STAR_CONTENT, SMART_STAR_CONTENT
)
# **strong**
Expand Down
2 changes: 1 addition & 1 deletion pymdownx/blocks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def register(self, b, config):
"""Register a block."""

if b.NAME in self.blocks:
raise ValueError('The block name {} is already registered!'.format(b.NAME))
raise ValueError(f'The block name {b.NAME} is already registered!')
self.blocks[b.NAME] = b
self.config[b.NAME] = config

Expand Down
18 changes: 9 additions & 9 deletions pymdownx/blocks/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _type_multi(value, types=None):
except ValueError: # noqa: PERF203
pass

raise ValueError("Type '{}' did not match any of the provided types".format(type(value)))
raise ValueError(f"Type '{type(value)}' did not match any of the provided types")


def type_multi(*args):
Expand All @@ -46,18 +46,18 @@ def type_none(value):
"""Ensure type None or fail."""

if value is not None:
raise ValueError('{} is not None'.format(type(value)))
raise ValueError(f'{type(value)} is not None')


def _ranged_number(value, minimum, maximum, number_type):
"""Check the range of the given number type."""

value = number_type(value)
if minimum is not None and value < minimum:
raise ValueError('{} is not greater than {}'.format(value, minimum))
raise ValueError(f'{value} is not greater than {minimum}')

if maximum is not None and value > maximum:
raise ValueError('{} is not greater than {}'.format(value, minimum))
raise ValueError(f'{value} is not greater than {minimum}')

return value

Expand All @@ -66,7 +66,7 @@ def type_number(value):
"""Ensure type number or fail."""

if not isinstance(value, (float, int)):
raise ValueError("Could not convert type {} to a number".format(type(value)))
raise ValueError(f"Could not convert type {type(value)} to a number")

return value

Expand All @@ -76,7 +76,7 @@ def type_integer(value):

if not isinstance(value, int):
if not isinstance(value, float) or not value.is_integer():
raise ValueError("Could not convert type {} to an integer".format(type(value)))
raise ValueError(f"Could not convert type {type(value)} to an integer")
value = int(value)

return value
Expand All @@ -98,7 +98,7 @@ def type_boolean(value):
"""Ensure type boolean or fail."""

if not isinstance(value, bool):
raise ValueError("Could not convert type {} to a boolean".format(type(value)))
raise ValueError(f"Could not convert type {type(value)} to a boolean")
return value


Expand All @@ -111,7 +111,7 @@ def type_string(value):
if isinstance(value, str):
return value

raise ValueError("Could not convert type {} to a string".format(type(value)))
raise ValueError(f"Could not convert type {type(value)} to a string")


def type_string_insensitive(value):
Expand Down Expand Up @@ -151,7 +151,7 @@ def _string_in(value, accepted, string_type):

value = string_type(value)
if value not in accepted:
raise ValueError('{} not found in {}'.format(value, str(accepted)))
raise ValueError(f'{value} not found in {accepted!s}')
return value


Expand Down
8 changes: 4 additions & 4 deletions pymdownx/blocks/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Whitespace
WS = r'(?:[ \t])'
# CSS escapes
CSS_ESCAPES = r'(?:\\(?:[a-f0-9]{{1,6}}{ws}?|[^\r\n\f]|$))'.format(ws=WS)
CSS_ESCAPES = fr'(?:\\(?:[a-f0-9]{{1,6}}{WS}?|[^\r\n\f]|$))'
# CSS Identifier
IDENTIFIER = r'''
(?:(?:-?(?:[^\x00-\x2f\x30-\x40\x5B-\x5E\x60\x7B-\x9f])+|--)
Expand All @@ -24,9 +24,9 @@
'''.format(ws=WS, value=VALUE)
# Selector patterns
# IDs (`#id`)
PAT_ID = r'\#{ident}'.format(ident=IDENTIFIER)
PAT_ID = fr'\#{IDENTIFIER}'
# Classes (`.class`)
PAT_CLASS = r'\.{ident}'.format(ident=IDENTIFIER)
PAT_CLASS = fr'\.{IDENTIFIER}'
# Attributes (`[attr]`, `[attr=value]`, etc.)
PAT_ATTR = r'''
\[(?:{ws}*(?P<attr_name>{ident}){attr})+{ws}*\]
Expand All @@ -36,7 +36,7 @@
RE_ID = re.compile(PAT_ID, flags=re.I | re.X)
RE_CLASS = re.compile(PAT_CLASS, flags=re.I | re.X)
RE_ATTRS = re.compile(PAT_ATTR, flags=re.I | re.X)
RE_ATTR = re.compile(r'(?P<attr_name>{ident}){attr}'.format(ident=IDENTIFIER, attr=ATTR), flags=re.I | re.X)
RE_ATTR = re.compile(fr'(?P<attr_name>{IDENTIFIER}){ATTR}', flags=re.I | re.X)

ATTRIBUTES = {'id': RE_ID, 'class': RE_CLASS, 'attr': RE_ATTRS}

Expand Down
2 changes: 1 addition & 1 deletion pymdownx/blocks/tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def on_create(self, parent):
attributes['checked'] = 'checked'
# Remove any previously assigned "checked states" to siblings
for i in tab_group.findall('input'):
if i.attrib.get('name', '') == '__tabbed_{}'.format(tab_set):
if i.attrib.get('name', '') == f'__tabbed_{tab_set}':
if 'checked' in i.attrib:
del i.attrib['checked']

Expand Down
10 changes: 5 additions & 5 deletions pymdownx/caret.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
# `^^^ins,sup^^^`
INS_SUP = r'(\^{3})(?!\s)(\^{1,2}|[^\^\s]+?)(?<!\s)\1'
# `^^^ins,sup^ins^^`
INS_SUP2 = r'(\^{3})(?![\s\^])%s(?<!\s)\^%s(?<!\s)\^{2}' % (CONTENT, CONTENT2)
INS_SUP2 = r'(\^{{3}})(?![\s\^]){}(?<!\s)\^{}(?<!\s)\^{{2}}'.format(CONTENT, CONTENT2)
# `^^^sup,ins^^sup^`
SUP_INS = r'(\^{3})(?![\s\^])%s(?<!\s)\^{2}%s(?<!\s)\^' % (CONTENT, CONTENT)
SUP_INS = r'(\^{{3}})(?![\s\^]){}(?<!\s)\^{{2}}{}(?<!\s)\^'.format(CONTENT, CONTENT)
# `^^ins^sup,ins^^^`
INS_SUP3 = r'(\^{2})(?![\s\^])%s\^(?![\s\^])%s(?<!\s)\^{3}' % (CONTENT2, CONTENT)
INS_SUP3 = r'(\^{{2}})(?![\s\^]){}\^(?![\s\^]){}(?<!\s)\^{{3}}'.format(CONTENT2, CONTENT)
# `^^ins^^`
INS = r'(\^{2})(?!\s)%s(?<!\s)\1' % CONTENT2
# `^sup^`
Expand All @@ -58,12 +58,12 @@
SMART_INS_SUP = r'(\^{3})(?![\s\^])%s(?<!\s)\1' % CONTENT
# `^^^ins,sup^ ins^^`
SMART_INS_SUP2 = \
r'(\^{3})(?![\s\^])%s(?<!\s)\^(?:(?=_)|(?![\w\^]))%s(?<!\s)\^{2}' % (
r'(\^{{3}})(?![\s\^]){}(?<!\s)\^(?:(?=_)|(?![\w\^])){}(?<!\s)\^{{2}}'.format(
CONTENT, SMART_CONTENT
)
# `^^^sup,ins^^ sup^`
SMART_SUP_INS = \
r'(\^{3})(?![\s\^])%s(?<!\s)\^{2}(?:(?=_)|(?![\w\^]))%s(?<!\s)\^' % (
r'(\^{{3}})(?![\s\^]){}(?<!\s)\^{{2}}(?:(?=_)|(?![\w\^])){}(?<!\s)\^'.format(
CONTENT, CONTENT
)
# `^^ins^^`
Expand Down
20 changes: 10 additions & 10 deletions pymdownx/critic.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@

CRITIC_KEY = "czjqqkd:%s"
CRITIC_PLACEHOLDER = CRITIC_KEY % r'[0-9]+'
SINGLE_CRITIC_PLACEHOLDER = r'%(stx)s(?P<key>%(key)s)%(etx)s' % {
"key": CRITIC_PLACEHOLDER, "stx": STX, "etx": ETX
}
SINGLE_CRITIC_PLACEHOLDER = r'{stx}(?P<key>{key}){etx}'.format(
key=CRITIC_PLACEHOLDER, stx=STX, etx=ETX
)
CRITIC_PLACEHOLDERS = r'''(?x)
(?:
(?P<block>\<p\>(?P<block_keys>(?:%(stx)s%(key)s%(etx)s)+)\</p\>) |
%(single)s
(?P<block>\<p\>(?P<block_keys>(?:{stx}{key}{etx})+)\</p\>) |
{single}
)
'''.format(
key=CRITIC_PLACEHOLDER, single=SINGLE_CRITIC_PLACEHOLDER,
stx=STX, etx=ETX
)
''' % {
"key": CRITIC_PLACEHOLDER, "single": SINGLE_CRITIC_PLACEHOLDER,
"stx": STX, "etx": ETX
}
ALL_CRITICS = r'''(?x)
((?P<critic>(?P<open>\{)
(?:
Expand Down Expand Up @@ -83,7 +83,7 @@
RE_BLOCK_SEP = re.compile(r'^(?:\r?\n){2,}$')


class CriticStash(object):
class CriticStash:
"""Stash critic marks until ready."""

def __init__(self, stash_key):
Expand Down
6 changes: 3 additions & 3 deletions pymdownx/emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def to_png(index, shortname, alias, uc, alt, title, category, options, md):
else: # pragma: no cover
image_path = options.get('non_standard_image_path', def_non_std_image_path)

src = "%s%s.png" % (
src = "{}{}.png".format(
image_path,
uc if is_unicode else shortname[1:-1]
)
Expand Down Expand Up @@ -156,7 +156,7 @@ def to_svg(index, shortname, alias, uc, alt, title, category, options, md):
attributes = {
"class": options.get('classes', index),
"alt": alt,
"src": "%s%s.svg" % (
"src": "{}{}.svg".format(
options.get('image_path', svg_path),
uc
)
Expand Down Expand Up @@ -203,7 +203,7 @@ def to_svg_sprite(index, shortname, alias, uc, alt, title, category, options, md
```
"""

xlink_href = '%s#emoji-%s' % (
xlink_href = '{}#emoji-{}'.format(
options.get('image_path', './../assets/sprites/emojione.sprites.svg'), uc
)
svg = etree.Element("svg", {"class": options.get('classes', index)})
Expand Down
2 changes: 1 addition & 1 deletion pymdownx/escapeall.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def handleMatch(self, m, data):
elif char in (STX, ETX):
escape = char
else:
escape = '%s%s%s' % (md_util.STX, util.get_ord(char), md_util.ETX)
escape = '{}{}{}'.format(md_util.STX, util.get_ord(char), md_util.ETX)
return escape, m.start(0), m.end(0)


Expand Down
12 changes: 6 additions & 6 deletions pymdownx/highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def _wrap_tablelinenos(self, inner):
yield t, self.RE_TABLE_NUMS.sub(r'\1<span></span>', line)


class Highlight(object):
class Highlight:
"""Highlight class."""

def __init__(
Expand Down Expand Up @@ -376,7 +376,7 @@ def highlight(
temp = []
for k, v in attrs.items():
if k.startswith('data-'):
temp.append('{k}="{v}"'.format(k=k, v=v))
temp.append(f'{k}="{v}"')
attr_str = ' ' + ' '.join(temp) if temp else ''

# Setup line specific settings.
Expand Down Expand Up @@ -410,9 +410,9 @@ def highlight(
hl_lines=hl_lines,
wrapcode=True,
filename=title if not inline else "",
linespans="{}-{}".format(self.line_spans, lineno_id) if self.line_spans and not inline else '',
linespans=f"{self.line_spans}-{lineno_id}" if self.line_spans and not inline else '',
lineanchors=(
"{}-{}".format(self.line_anchors, lineno_id) if self.line_anchors and not inline else ""
f"{self.line_anchors}-{lineno_id}" if self.line_anchors and not inline else ""
),
anchorlinenos=self.anchor_linenums if not inline else False
)
Expand All @@ -435,7 +435,7 @@ def highlight(
else:
classes = ' ' + m.group(2).lstrip() if m.group(2) else ''

code = '{}<{}{}{}{}>{}'.format(code[:start], m.group(1), id_str, classes, attr_str, code[end:])
code = f'{code[:start]}<{m.group(1)}{id_str}{classes}{attr_str}>{code[end:]}'

elif inline:
# Format inline code for a JavaScript Syntax Highlighter by specifying language.
Expand All @@ -454,7 +454,7 @@ def highlight(
class_names.insert(0, self.language_prefix + language)
class_str = CLASS_ATTR.format(' '.join(class_names)) if class_names else ''
id_str = ID_ATTR.format(id_value) if id_value else ''
attr_str = ' ' + ' '.join('{k}="{v}"'.format(k=k, v=v) for k, v in attrs.items()) if attrs else ''
attr_str = ' ' + ' '.join(f'{k}="{v}"' for k, v in attrs.items()) if attrs else ''
if not self.code_attr_on_pre:
highlight_class = (CLASS_ATTR.format(css_class)) if css_class else ''
code = CODE_WRAP.format(highlight_class, id_str, class_str, attr_str, self.escape(src))
Expand Down
2 changes: 1 addition & 1 deletion pymdownx/inlinehilite.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import xml.etree.ElementTree as etree
import functools

ESCAPED_BSLASH = '%s%s%s' % (md_util.STX, ord('\\'), md_util.ETX)
ESCAPED_BSLASH = '{}{}{}'.format(md_util.STX, ord('\\'), md_util.ETX)
DOUBLE_BSLASH = '\\\\'
BACKTICK_CODE_RE = r'''(?x)
(?:
Expand Down
Loading

0 comments on commit c8856a3

Please sign in to comment.