Skip to content

Commit 6dbb618

Browse files
authored
Shrink 'any-generics' whitelist for the pycode module (#10868)
1 parent b437f09 commit 6dbb618

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ module = [
198198
"sphinx.highlighting",
199199
"sphinx.jinja2glue",
200200
"sphinx.locale",
201-
"sphinx.pycode.*",
202201
"sphinx.registry",
203202
"sphinx.roles",
204203
"sphinx.search.*",

sphinx/pycode/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
from collections import OrderedDict
66
from importlib import import_module
77
from inspect import Signature
8-
from io import StringIO
98
from os import path
10-
from typing import IO, Any, Dict, List, Optional, Tuple
9+
from typing import Any, Dict, List, Optional, Tuple
1110
from zipfile import ZipFile
1211

1312
from sphinx.errors import PycodeError
@@ -76,16 +75,17 @@ def get_module_source(modname: str) -> Tuple[Optional[str], Optional[str]]:
7675
@classmethod
7776
def for_string(cls, string: str, modname: str, srcname: str = '<string>'
7877
) -> "ModuleAnalyzer":
79-
return cls(StringIO(string), modname, srcname)
78+
return cls(string, modname, srcname)
8079

8180
@classmethod
8281
def for_file(cls, filename: str, modname: str) -> "ModuleAnalyzer":
8382
if ('file', filename) in cls.cache:
8483
return cls.cache['file', filename]
8584
try:
8685
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
8989
except Exception as err:
9090
if '.egg' + path.sep in filename:
9191
obj = cls.cache['file', filename] = cls.for_egg(filename, modname)
@@ -124,12 +124,12 @@ def for_module(cls, modname: str) -> "ModuleAnalyzer":
124124
cls.cache['module', modname] = obj
125125
return obj
126126

127-
def __init__(self, source: IO, modname: str, srcname: str) -> None:
127+
def __init__(self, source: str, modname: str, srcname: str) -> None:
128128
self.modname = modname # name of the module
129129
self.srcname = srcname # name of the source file
130130

131131
# cache the source code as well
132-
self.code = source.read()
132+
self.code = source
133133

134134
self._analyzed = False
135135

sphinx/pycode/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ def __init__(self, lines: List[str]) -> None:
464464
super().__init__(lines)
465465
self.decorator: Optional[Token] = None
466466
self.context: List[str] = []
467-
self.indents: List = []
467+
self.indents: List[Tuple[str, Optional[str], Optional[int]]] = []
468468
self.definitions: Dict[str, Tuple[str, int, int]] = {}
469469

470470
def add_definition(self, name: str, entry: Tuple[str, int, int]) -> None:

0 commit comments

Comments
 (0)