Skip to content

Commit 7de5b2a

Browse files
zzzeekGerrit Code Review
authored andcommitted
Merge "Remove Python 2 residue; use Python 3 idioms" into main
2 parents d5312eb + 1b30aa5 commit 7de5b2a

17 files changed

Lines changed: 77 additions & 104 deletions

doc/build/conf.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# Mako documentation build configuration file
43
#
@@ -78,8 +77,8 @@
7877
master_doc = "index"
7978

8079
# General information about the project.
81-
project = u"Mako"
82-
copyright = u"the Mako authors and contributors"
80+
project = "Mako"
81+
copyright = "the Mako authors and contributors"
8382

8483
# The version info for the project you're documenting, acts as replacement for
8584
# |version| and |release|, also used in various other places throughout the
@@ -89,7 +88,7 @@
8988
version = mako.__version__
9089
# The full version, including alpha/beta/rc tags.
9190
release = "1.1.5"
92-
91+
release_date = None
9392
# The language for content autogenerated by Sphinx. Refer to documentation
9493
# for a list of supported languages.
9594
# language = None
@@ -230,8 +229,8 @@
230229
(
231230
"index",
232231
"mako_%s.tex" % release.replace(".", "_"),
233-
u"Mako Documentation",
234-
u"Mike Bayer",
232+
"Mako Documentation",
233+
"Mike Bayer",
235234
"manual",
236235
)
237236
]
@@ -269,16 +268,16 @@
269268

270269
# One entry per manual page. List of tuples
271270
# (source start file, name, description, authors, manual section).
272-
man_pages = [("index", "mako", u"Mako Documentation", [u"Mako authors"], 1)]
271+
man_pages = [("index", "mako", "Mako Documentation", ["Mako authors"], 1)]
273272

274273

275274
# -- Options for Epub output ---------------------------------------------------
276275

277276
# Bibliographic Dublin Core info.
278-
epub_title = u"Mako"
279-
epub_author = u"Mako authors"
280-
epub_publisher = u"Mako authors"
281-
epub_copyright = u"Mako authors"
277+
epub_title = "Mako"
278+
epub_author = "Mako authors"
279+
epub_publisher = "Mako authors"
280+
epub_copyright = "Mako authors"
282281

283282
# The language of the text. It defaults to the language option
284283
# or en if the language is not set.

mako/ast.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def __init__(self, code, **exception_kwargs):
107107
"Unsupported control keyword: '%s'" % keyword,
108108
**exception_kwargs,
109109
)
110-
super(PythonFragment, self).__init__(code, **exception_kwargs)
110+
super().__init__(code, **exception_kwargs)
111111

112112

113113
class FunctionDecl:
@@ -199,6 +199,4 @@ class FunctionArgs(FunctionDecl):
199199
"""the argument portion of a function declaration"""
200200

201201
def __init__(self, code, **kwargs):
202-
super(FunctionArgs, self).__init__(
203-
"def ANON(%s):pass" % code, **kwargs
204-
)
202+
super().__init__("def ANON(%s):pass" % code, **kwargs)

mako/cmd.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# This module is part of Mako and is released under
55
# the MIT License: http://www.opensource.org/licenses/mit-license.php
66
from argparse import ArgumentParser
7-
import io
87
from os.path import dirname
98
from os.path import isfile
109
import sys
@@ -92,9 +91,7 @@ def cmdline(argv=None):
9291
_exit()
9392
else:
9493
if output_file:
95-
io.open(output_file, "wt", encoding=output_encoding).write(
96-
rendered
97-
)
94+
open(output_file, "wt", encoding=output_encoding).write(rendered)
9895
else:
9996
sys.stdout.write(rendered)
10097

mako/compat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ def inspect_getargspec(func):
2424
if inspect.ismethod(func):
2525
func = func.__func__
2626
if not inspect.isfunction(func):
27-
raise TypeError("{!r} is not a Python function".format(func))
27+
raise TypeError(f"{func!r} is not a Python function")
2828

2929
co = func.__code__
3030
if not inspect.iscode(co):
31-
raise TypeError("{!r} is not a code object".format(co))
31+
raise TypeError(f"{co!r} is not a code object")
3232

3333
nargs = co.co_argcount
3434
names = co.co_varnames

mako/ext/babelplugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(self, keywords, comment_tags, options):
2020
"input_encoding", options.get("encoding", None)
2121
),
2222
}
23-
super(BabelMakoExtractor, self).__init__()
23+
super().__init__()
2424

2525
def __call__(self, fileobj):
2626
return self.process_file(fileobj)

mako/ext/beaker_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self, cache):
4040
_beaker_cache = cache.template.cache_args["manager"]
4141
else:
4242
_beaker_cache = beaker_cache.CacheManager()
43-
super(BeakerCacheImpl, self).__init__(cache)
43+
super().__init__(cache)
4444

4545
def _get_cache(self, **kw):
4646
expiretime = kw.pop("timeout", None)

mako/ext/pygmentplugin.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,33 +106,31 @@ class MakoHtmlLexer(DelegatingLexer):
106106
aliases = ["html+mako"]
107107

108108
def __init__(self, **options):
109-
super(MakoHtmlLexer, self).__init__(HtmlLexer, MakoLexer, **options)
109+
super().__init__(HtmlLexer, MakoLexer, **options)
110110

111111

112112
class MakoXmlLexer(DelegatingLexer):
113113
name = "XML+Mako"
114114
aliases = ["xml+mako"]
115115

116116
def __init__(self, **options):
117-
super(MakoXmlLexer, self).__init__(XmlLexer, MakoLexer, **options)
117+
super().__init__(XmlLexer, MakoLexer, **options)
118118

119119

120120
class MakoJavascriptLexer(DelegatingLexer):
121121
name = "JavaScript+Mako"
122122
aliases = ["js+mako", "javascript+mako"]
123123

124124
def __init__(self, **options):
125-
super(MakoJavascriptLexer, self).__init__(
126-
JavascriptLexer, MakoLexer, **options
127-
)
125+
super().__init__(JavascriptLexer, MakoLexer, **options)
128126

129127

130128
class MakoCssLexer(DelegatingLexer):
131129
name = "CSS+Mako"
132130
aliases = ["css+mako"]
133131

134132
def __init__(self, **options):
135-
super(MakoCssLexer, self).__init__(CssLexer, MakoLexer, **options)
133+
super().__init__(CssLexer, MakoLexer, **options)
136134

137135

138136
pygments_html_formatter = HtmlFormatter(

mako/parsetree.py

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class TemplateNode(Node):
5050
"""a 'container' node that stores the overall collection of nodes."""
5151

5252
def __init__(self, filename):
53-
super(TemplateNode, self).__init__("", 0, 0, filename)
53+
super().__init__("", 0, 0, filename)
5454
self.nodes = []
5555
self.page_attributes = {}
5656

@@ -79,7 +79,7 @@ class ControlLine(Node):
7979
has_loop_context = False
8080

8181
def __init__(self, keyword, isend, text, **kwargs):
82-
super(ControlLine, self).__init__(**kwargs)
82+
super().__init__(**kwargs)
8383
self.text = text
8484
self.keyword = keyword
8585
self.isend = isend
@@ -127,7 +127,7 @@ class Text(Node):
127127
"""defines plain text in the template."""
128128

129129
def __init__(self, content, **kwargs):
130-
super(Text, self).__init__(**kwargs)
130+
super().__init__(**kwargs)
131131
self.content = content
132132

133133
def __repr__(self):
@@ -152,7 +152,7 @@ class Code(Node):
152152
"""
153153

154154
def __init__(self, text, ismodule, **kwargs):
155-
super(Code, self).__init__(**kwargs)
155+
super().__init__(**kwargs)
156156
self.text = text
157157
self.ismodule = ismodule
158158
self.code = ast.PythonCode(text, **self.exception_kwargs)
@@ -179,7 +179,7 @@ class Comment(Node):
179179
"""
180180

181181
def __init__(self, text, **kwargs):
182-
super(Comment, self).__init__(**kwargs)
182+
super().__init__(**kwargs)
183183
self.text = text
184184

185185
def __repr__(self):
@@ -194,7 +194,7 @@ class Expression(Node):
194194
"""
195195

196196
def __init__(self, text, escapes, **kwargs):
197-
super(Expression, self).__init__(**kwargs)
197+
super().__init__(**kwargs)
198198
self.text = text
199199
self.escapes = escapes
200200
self.escapes_code = ast.ArgumentList(escapes, **self.exception_kwargs)
@@ -228,7 +228,7 @@ class _TagMeta(type):
228228
def __init__(cls, clsname, bases, dict_):
229229
if getattr(cls, "__keyword__", None) is not None:
230230
cls._classmap[cls.__keyword__] = cls
231-
super(_TagMeta, cls).__init__(clsname, bases, dict_)
231+
super().__init__(clsname, bases, dict_)
232232

233233
def __call__(cls, keyword, attributes, **kwargs):
234234
if ":" in keyword:
@@ -293,7 +293,7 @@ def __init__(
293293
other arguments passed to the Node superclass (lineno, pos)
294294
295295
"""
296-
super(Tag, self).__init__(**kwargs)
296+
super().__init__(**kwargs)
297297
self.keyword = keyword
298298
self.attributes = attributes
299299
self._parse_attributes(expressions, nonexpressions)
@@ -377,7 +377,7 @@ class IncludeTag(Tag):
377377
__keyword__ = "include"
378378

379379
def __init__(self, keyword, attributes, **kwargs):
380-
super(IncludeTag, self).__init__(
380+
super().__init__(
381381
keyword,
382382
attributes,
383383
("file", "import", "args"),
@@ -396,16 +396,14 @@ def undeclared_identifiers(self):
396396
identifiers = self.page_args.undeclared_identifiers.difference(
397397
{"__DUMMY"}
398398
).difference(self.page_args.declared_identifiers)
399-
return identifiers.union(
400-
super(IncludeTag, self).undeclared_identifiers()
401-
)
399+
return identifiers.union(super().undeclared_identifiers())
402400

403401

404402
class NamespaceTag(Tag):
405403
__keyword__ = "namespace"
406404

407405
def __init__(self, keyword, attributes, **kwargs):
408-
super(NamespaceTag, self).__init__(
406+
super().__init__(
409407
keyword,
410408
attributes,
411409
("file",),
@@ -435,9 +433,7 @@ class TextTag(Tag):
435433
__keyword__ = "text"
436434

437435
def __init__(self, keyword, attributes, **kwargs):
438-
super(TextTag, self).__init__(
439-
keyword, attributes, (), ("filter"), (), **kwargs
440-
)
436+
super().__init__(keyword, attributes, (), ("filter"), (), **kwargs)
441437
self.filter_args = ast.ArgumentList(
442438
attributes.get("filter", ""), **self.exception_kwargs
443439
)
@@ -456,7 +452,7 @@ def __init__(self, keyword, attributes, **kwargs):
456452
c for c in attributes if c.startswith("cache_")
457453
]
458454

459-
super(DefTag, self).__init__(
455+
super().__init__(
460456
keyword,
461457
attributes,
462458
expressions,
@@ -519,7 +515,7 @@ def __init__(self, keyword, attributes, **kwargs):
519515
c for c in attributes if c.startswith("cache_")
520516
]
521517

522-
super(BlockTag, self).__init__(
518+
super().__init__(
523519
keyword,
524520
attributes,
525521
expressions,
@@ -575,7 +571,7 @@ class CallTag(Tag):
575571
__keyword__ = "call"
576572

577573
def __init__(self, keyword, attributes, **kwargs):
578-
super(CallTag, self).__init__(
574+
super().__init__(
579575
keyword, attributes, ("args"), ("expr",), ("expr",), **kwargs
580576
)
581577
self.expression = attributes["expr"]
@@ -595,7 +591,7 @@ def undeclared_identifiers(self):
595591

596592
class CallNamespaceTag(Tag):
597593
def __init__(self, namespace, defname, attributes, **kwargs):
598-
super(CallNamespaceTag, self).__init__(
594+
super().__init__(
599595
namespace + ":" + defname,
600596
attributes,
601597
tuple(attributes.keys()) + ("args",),
@@ -632,7 +628,7 @@ class InheritTag(Tag):
632628
__keyword__ = "inherit"
633629

634630
def __init__(self, keyword, attributes, **kwargs):
635-
super(InheritTag, self).__init__(
631+
super().__init__(
636632
keyword, attributes, ("file",), (), ("file",), **kwargs
637633
)
638634

@@ -648,9 +644,7 @@ def __init__(self, keyword, attributes, **kwargs):
648644
"enable_loop",
649645
] + [c for c in attributes if c.startswith("cache_")]
650646

651-
super(PageTag, self).__init__(
652-
keyword, attributes, expressions, (), (), **kwargs
653-
)
647+
super().__init__(keyword, attributes, expressions, (), (), **kwargs)
654648
self.body_decl = ast.FunctionArgs(
655649
attributes.get("args", ""), **self.exception_kwargs
656650
)

test/ext/test_babelplugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def test_extract_utf8(self):
103103
)
104104
self.addCleanup(mako_tmpl.close)
105105
message = next(
106-
extract(mako_tmpl, set(["_", None]), [], {"encoding": "utf-8"})
106+
extract(mako_tmpl, {"_", None}, [], {"encoding": "utf-8"})
107107
)
108108
assert message == (1, "_", "K\xf6ln", [])
109109

@@ -114,7 +114,7 @@ def test_extract_cp1251(self):
114114
)
115115
self.addCleanup(mako_tmpl.close)
116116
message = next(
117-
extract(mako_tmpl, set(["_", None]), [], {"encoding": "cp1251"})
117+
extract(mako_tmpl, {"_", None}, [], {"encoding": "cp1251"})
118118
)
119119
# "test" in Rusian. File encoding is cp1251 (aka "windows-1251")
120120
assert message == (1, "_", "\u0442\u0435\u0441\u0442", [])

0 commit comments

Comments
 (0)