mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
refactor: pycode: Use OrderedDict to store variable comments
It is worthy to keep the order of analyzer.attr_docs to generate document in reproducible. So this uses OrderedDict explicitly to do that. It also helps python3.5 environment.
This commit is contained in:
parent
68c732e97c
commit
b6bf2b88ce
@ -11,6 +11,7 @@
|
||||
import re
|
||||
import tokenize
|
||||
import warnings
|
||||
from collections import OrderedDict
|
||||
from importlib import import_module
|
||||
from inspect import Signature
|
||||
from io import StringIO
|
||||
@ -156,7 +157,7 @@ class ModuleAnalyzer:
|
||||
parser = Parser(self.code, self._encoding)
|
||||
parser.parse()
|
||||
|
||||
self.attr_docs = {}
|
||||
self.attr_docs = OrderedDict()
|
||||
for (scope, comment) in parser.comments.items():
|
||||
if comment:
|
||||
self.attr_docs[scope] = comment.splitlines() + ['']
|
||||
|
@ -12,6 +12,7 @@ import itertools
|
||||
import re
|
||||
import sys
|
||||
import tokenize
|
||||
from collections import OrderedDict
|
||||
from inspect import Signature
|
||||
from token import NAME, NEWLINE, INDENT, DEDENT, NUMBER, OP, STRING
|
||||
from tokenize import COMMENT, NL
|
||||
@ -228,7 +229,7 @@ class VariableCommentPicker(ast.NodeVisitor):
|
||||
self.context = [] # type: List[str]
|
||||
self.current_classes = [] # type: List[str]
|
||||
self.current_function = None # type: ast.FunctionDef
|
||||
self.comments = {} # type: Dict[Tuple[str, str], str]
|
||||
self.comments = OrderedDict() # type: Dict[Tuple[str, str], str]
|
||||
self.annotations = {} # type: Dict[Tuple[str, str], str]
|
||||
self.previous = None # type: ast.AST
|
||||
self.deforders = {} # type: Dict[str, int]
|
||||
|
Loading…
Reference in New Issue
Block a user