Shrink 'any-generics' whitelist for the pycode module (#10868)

This commit is contained in:
danieleades 2022-09-28 09:13:48 +01:00 committed by GitHub
parent b437f094a7
commit 6dbb618834
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 9 deletions

View File

@ -198,7 +198,6 @@ module = [
"sphinx.highlighting",
"sphinx.jinja2glue",
"sphinx.locale",
"sphinx.pycode.*",
"sphinx.registry",
"sphinx.roles",
"sphinx.search.*",

View File

@ -5,9 +5,8 @@ import tokenize
from collections import OrderedDict
from importlib import import_module
from inspect import Signature
from io import StringIO
from os import path
from typing import IO, Any, Dict, List, Optional, Tuple
from typing import Any, Dict, List, Optional, Tuple
from zipfile import ZipFile
from sphinx.errors import PycodeError
@ -76,7 +75,7 @@ class ModuleAnalyzer:
@classmethod
def for_string(cls, string: str, modname: str, srcname: str = '<string>'
) -> "ModuleAnalyzer":
return cls(StringIO(string), modname, srcname)
return cls(string, modname, srcname)
@classmethod
def for_file(cls, filename: str, modname: str) -> "ModuleAnalyzer":
@ -84,8 +83,9 @@ class ModuleAnalyzer:
return cls.cache['file', filename]
try:
with tokenize.open(filename) as f:
obj = cls(f, modname, filename)
cls.cache['file', filename] = obj
string = f.read()
obj = cls(string, modname, filename)
cls.cache['file', filename] = obj
except Exception as err:
if '.egg' + path.sep in filename:
obj = cls.cache['file', filename] = cls.for_egg(filename, modname)
@ -124,12 +124,12 @@ class ModuleAnalyzer:
cls.cache['module', modname] = obj
return obj
def __init__(self, source: IO, modname: str, srcname: str) -> None:
def __init__(self, source: str, modname: str, srcname: str) -> None:
self.modname = modname # name of the module
self.srcname = srcname # name of the source file
# cache the source code as well
self.code = source.read()
self.code = source
self._analyzed = False

View File

@ -464,7 +464,7 @@ class DefinitionFinder(TokenProcessor):
super().__init__(lines)
self.decorator: Optional[Token] = None
self.context: List[str] = []
self.indents: List = []
self.indents: List[Tuple[str, Optional[str], Optional[int]]] = []
self.definitions: Dict[str, Tuple[str, int, int]] = {}
def add_definition(self, name: str, entry: Tuple[str, int, int]) -> None: