|
5 | 5 | from collections import OrderedDict
|
6 | 6 | from importlib import import_module
|
7 | 7 | from inspect import Signature
|
8 |
| -from io import StringIO |
9 | 8 | from os import path
|
10 |
| -from typing import IO, Any, Dict, List, Optional, Tuple |
| 9 | +from typing import Any, Dict, List, Optional, Tuple |
11 | 10 | from zipfile import ZipFile
|
12 | 11 |
|
13 | 12 | from sphinx.errors import PycodeError
|
@@ -76,16 +75,17 @@ def get_module_source(modname: str) -> Tuple[Optional[str], Optional[str]]:
|
76 | 75 | @classmethod
|
77 | 76 | def for_string(cls, string: str, modname: str, srcname: str = '<string>'
|
78 | 77 | ) -> "ModuleAnalyzer":
|
79 |
| - return cls(StringIO(string), modname, srcname) |
| 78 | + return cls(string, modname, srcname) |
80 | 79 |
|
81 | 80 | @classmethod
|
82 | 81 | def for_file(cls, filename: str, modname: str) -> "ModuleAnalyzer":
|
83 | 82 | if ('file', filename) in cls.cache:
|
84 | 83 | return cls.cache['file', filename]
|
85 | 84 | try:
|
86 | 85 | with tokenize.open(filename) as f:
|
87 |
| - obj = cls(f, modname, filename) |
88 |
| - cls.cache['file', filename] = obj |
| 86 | + string = f.read() |
| 87 | + obj = cls(string, modname, filename) |
| 88 | + cls.cache['file', filename] = obj |
89 | 89 | except Exception as err:
|
90 | 90 | if '.egg' + path.sep in filename:
|
91 | 91 | obj = cls.cache['file', filename] = cls.for_egg(filename, modname)
|
@@ -124,12 +124,12 @@ def for_module(cls, modname: str) -> "ModuleAnalyzer":
|
124 | 124 | cls.cache['module', modname] = obj
|
125 | 125 | return obj
|
126 | 126 |
|
127 |
| - def __init__(self, source: IO, modname: str, srcname: str) -> None: |
| 127 | + def __init__(self, source: str, modname: str, srcname: str) -> None: |
128 | 128 | self.modname = modname # name of the module
|
129 | 129 | self.srcname = srcname # name of the source file
|
130 | 130 |
|
131 | 131 | # cache the source code as well
|
132 |
| - self.code = source.read() |
| 132 | + self.code = source |
133 | 133 |
|
134 | 134 | self._analyzed = False
|
135 | 135 |
|
|
0 commit comments