From 5bf25eb44529cb0546b9b690a142ca7529a062f0 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sat, 15 Dec 2018 15:43:44 -0800 Subject: Avoid respecifying default encoding for .encode()/.decode() calls In Python 3, both .encode() and .decode() default the encoding to 'utf-8'. See the docs: https://docs.python.org/3/library/stdtypes.html#str.encode https://docs.python.org/3/library/stdtypes.html#bytes.decode Simplify and shorten the code by using the default instead of respecifying it. --- sphinx/pycode/__init__.py | 2 +- sphinx/pycode/parser.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'sphinx/pycode') diff --git a/sphinx/pycode/__init__.py b/sphinx/pycode/__init__.py index e3e80772c..e2538ad27 100644 --- a/sphinx/pycode/__init__.py +++ b/sphinx/pycode/__init__.py @@ -55,7 +55,7 @@ class ModuleAnalyzer: eggpath, relpath = re.split('(?<=\\.egg)/', filename) try: with ZipFile(eggpath) as egg: - code = egg.read(relpath).decode('utf-8') + code = egg.read(relpath).decode() return cls.for_string(code, modname, filename) except Exception as exc: raise PycodeError('error opening %r' % filename, exc) diff --git a/sphinx/pycode/parser.py b/sphinx/pycode/parser.py index 71d7df781..0d0c3322f 100644 --- a/sphinx/pycode/parser.py +++ b/sphinx/pycode/parser.py @@ -480,7 +480,7 @@ class Parser: def parse_comments(self): # type: () -> None """Parse the code and pick up comments.""" - tree = ast.parse(self.code.encode('utf-8')) + tree = ast.parse(self.code.encode()) picker = VariableCommentPicker(self.code.splitlines(True), self.encoding) picker.visit(tree) self.comments = picker.comments -- cgit v1.2.1