summaryrefslogtreecommitdiff
path: root/sphinx/pycode/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/pycode/__init__.py')
-rw-r--r--sphinx/pycode/__init__.py26
1 files changed, 11 insertions, 15 deletions
diff --git a/sphinx/pycode/__init__.py b/sphinx/pycode/__init__.py
index fe6b5f7e1..e3e80772c 100644
--- a/sphinx/pycode/__init__.py
+++ b/sphinx/pycode/__init__.py
@@ -8,14 +8,11 @@
:copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
-from __future__ import print_function
import re
-from io import BytesIO
+from io import BytesIO, StringIO
from zipfile import ZipFile
-from six import StringIO
-
from sphinx.errors import PycodeError
from sphinx.pycode.parser import Parser
from sphinx.util import get_module_source, detect_encoding
@@ -23,23 +20,22 @@ from sphinx.util import get_module_source, detect_encoding
if False:
# For type annotation
from typing import Any, Dict, IO, List, Tuple # NOQA
- from sphinx.util.typing import unicode # NOQA
class ModuleAnalyzer:
# cache for analyzer objects -- caches both by module and file name
- cache = {} # type: Dict[Tuple[unicode, unicode], Any]
+ cache = {} # type: Dict[Tuple[str, str], Any]
@classmethod
def for_string(cls, string, modname, srcname='<string>'):
- # type: (unicode, unicode, unicode) -> ModuleAnalyzer
+ # type: (str, str, str) -> ModuleAnalyzer
if isinstance(string, bytes):
return cls(BytesIO(string), modname, srcname)
return cls(StringIO(string), modname, srcname, decoded=True)
@classmethod
def for_file(cls, filename, modname):
- # type: (unicode, unicode) -> ModuleAnalyzer
+ # type: (str, str) -> ModuleAnalyzer
if ('file', filename) in cls.cache:
return cls.cache['file', filename]
try:
@@ -55,7 +51,7 @@ class ModuleAnalyzer:
@classmethod
def for_egg(cls, filename, modname):
- # type: (unicode, unicode) -> ModuleAnalyzer
+ # type: (str, str) -> ModuleAnalyzer
eggpath, relpath = re.split('(?<=\\.egg)/', filename)
try:
with ZipFile(eggpath) as egg:
@@ -86,7 +82,7 @@ class ModuleAnalyzer:
return obj
def __init__(self, source, modname, srcname, decoded=False):
- # type: (IO, unicode, unicode, bool) -> None
+ # type: (IO, str, str, bool) -> None
self.modname = modname # name of the module
self.srcname = srcname # name of the source file
@@ -101,9 +97,9 @@ class ModuleAnalyzer:
self.code = source.read()
# will be filled by parse()
- self.attr_docs = None # type: Dict[Tuple[unicode, unicode], List[unicode]]
- self.tagorder = None # type: Dict[unicode, int]
- self.tags = None # type: Dict[unicode, Tuple[unicode, int, int]]
+ self.attr_docs = None # type: Dict[Tuple[str, str], List[str]]
+ self.tagorder = None # type: Dict[str, int]
+ self.tags = None # type: Dict[str, Tuple[str, int, int]]
def parse(self):
# type: () -> None
@@ -125,7 +121,7 @@ class ModuleAnalyzer:
raise PycodeError('parsing %r failed: %r' % (self.srcname, exc))
def find_attr_docs(self):
- # type: () -> Dict[Tuple[unicode, unicode], List[unicode]]
+ # type: () -> Dict[Tuple[str, str], List[str]]
"""Find class and module-level attributes and their documentation."""
if self.attr_docs is None:
self.parse()
@@ -133,7 +129,7 @@ class ModuleAnalyzer:
return self.attr_docs
def find_tags(self):
- # type: () -> Dict[unicode, Tuple[unicode, int, int]]
+ # type: () -> Dict[str, Tuple[str, int, int]]
"""Find class, function and method definitions and their location."""
if self.tags is None:
self.parse()