Browse Source

Upgrade Python syntax with pyupgrade https://github.com/asottile/pyupgrade

tags/v0.5.2
Hugo 5 years ago
parent
commit
e457b39f32
9 changed files with 13 additions and 13 deletions
  1. +2
    -2
      mwparserfromhell/nodes/extras/attribute.py
  2. +1
    -1
      mwparserfromhell/nodes/extras/parameter.py
  3. +3
    -3
      mwparserfromhell/nodes/html_entity.py
  4. +1
    -1
      mwparserfromhell/parser/__init__.py
  5. +1
    -1
      mwparserfromhell/parser/tokens.py
  6. +1
    -1
      mwparserfromhell/string_mixin.py
  7. +2
    -2
      scripts/memtest.py
  8. +1
    -1
      setup.py
  9. +1
    -1
      tests/_test_tokenizer.py

+ 2
- 2
mwparserfromhell/nodes/extras/attribute.py View File

@@ -40,7 +40,7 @@ class Attribute(StringMixIn):
pad_before_eq="", pad_after_eq="", check_quotes=True):
super(Attribute, self).__init__()
if check_quotes and not quotes and self._value_needs_quotes(value):
raise ValueError("given value {0!r} requires quotes".format(value))
raise ValueError("given value {!r} requires quotes".format(value))
self._name = name
self._value = value
self._quotes = quotes
@@ -79,7 +79,7 @@ class Attribute(StringMixIn):
"""Coerce a quote type into an acceptable value, or raise an error."""
orig, quotes = quotes, str(quotes) if quotes else None
if quotes not in [None, '"', "'"]:
raise ValueError("{0!r} is not a valid quote type".format(orig))
raise ValueError("{!r} is not a valid quote type".format(orig))
return quotes

@property


+ 1
- 1
mwparserfromhell/nodes/extras/parameter.py View File

@@ -41,7 +41,7 @@ class Parameter(StringMixIn):
def __init__(self, name, value, showkey=True):
super(Parameter, self).__init__()
if not showkey and not self.can_hide_key(name):
raise ValueError("key {0!r} cannot be hidden".format(name))
raise ValueError("key {!r} cannot be hidden".format(name))
self._name = name
self._value = value
self._showkey = showkey


+ 3
- 3
mwparserfromhell/nodes/html_entity.py View File

@@ -53,10 +53,10 @@ class HTMLEntity(Node):

def __unicode__(self):
if self.named:
return "&{0};".format(self.value)
return "&{};".format(self.value)
if self.hexadecimal:
return "&#{0}{1};".format(self.hex_char, self.value)
return "&#{0};".format(self.value)
return "&#{}{};".format(self.hex_char, self.value)
return "&#{};".format(self.value)

def __strip__(self, **kwargs):
if kwargs.get("normalize"):


+ 1
- 1
mwparserfromhell/parser/__init__.py View File

@@ -35,7 +35,7 @@ class ParserError(Exception):
can happen. Its appearance indicates a bug.
"""
def __init__(self, extra):
msg = "This is a bug and should be reported. Info: {0}.".format(extra)
msg = "This is a bug and should be reported. Info: {}.".format(extra)
super(ParserError, self).__init__(msg)




+ 1
- 1
mwparserfromhell/parser/tokens.py View File

@@ -44,7 +44,7 @@ class Token(dict):
args.append(key + "=" + repr(value[:97] + "..."))
else:
args.append(key + "=" + repr(value))
return "{0}({1})".format(type(self).__name__, ", ".join(args))
return "{}({})".format(type(self).__name__, ", ".join(args))

def __eq__(self, other):
return isinstance(other, type(self)) and dict.__eq__(self, other)


+ 1
- 1
mwparserfromhell/string_mixin.py View File

@@ -109,7 +109,7 @@ class StringMixIn(object):

def __getattr__(self, attr):
if not hasattr(str, attr):
raise AttributeError("{0!r} object has no attribute {1!r}".format(
raise AttributeError("{!r} object has no attribute {!r}".format(
type(self).__name__, attr))
return getattr(self.__unicode__(), attr)



+ 2
- 2
scripts/memtest.py View File

@@ -80,7 +80,7 @@ class MemoryTest(object):
raw = raw.encode("raw_unicode_escape")
data["input"] = raw.decode("unicode_escape")
number = str(counter).zfill(digits)
fname = "test_{0}{1}_{2}".format(name, number, data["name"])
fname = "test_{}{}_{}".format(name, number, data["name"])
self._tests.append((fname, data["input"]))
counter += 1

@@ -117,7 +117,7 @@ class MemoryTest(object):
tmpl = "{0}LEAKING{1}: {2:n} bytes, {3:.2%} inc ({4:n} bytes/loop)"
sys.stdout.write(tmpl.format(Color.YELLOW, Color.RESET, d, p, bpt))
else:
sys.stdout.write("{0}OK{1}".format(Color.GREEN, Color.RESET))
sys.stdout.write("{}OK{}".format(Color.GREEN, Color.RESET))

def run(self):
"""Run the memory test suite."""


+ 1
- 1
setup.py View File

@@ -89,7 +89,7 @@ setup(
url = "https://github.com/earwig/mwparserfromhell",
description = "MWParserFromHell is a parser for MediaWiki wikicode.",
long_description = long_docs,
download_url = "https://github.com/earwig/mwparserfromhell/tarball/v{0}".format(__version__),
download_url = "https://github.com/earwig/mwparserfromhell/tarball/v{}".format(__version__),
keywords = "earwig mwparserfromhell wikipedia wiki mediawiki wikicode template parsing",
license = "MIT License",
classifiers = [


+ 1
- 1
tests/_test_tokenizer.py View File

@@ -118,7 +118,7 @@ class TokenizerTestCase(object):
if restrict and data["name"] != restrict:
continue

fname = "test_{0}{1}_{2}".format(name, number, data["name"])
fname = "test_{}{}_{}".format(name, number, data["name"])
meth = cls._build_test_method(fname, data)
setattr(cls, fname, meth)



Loading…
Cancel
Save