Skip to content

Commit 29d7166

Browse files
committed
Drop OrderedDict
Since Python 3.7, dicts maintain insertion order.
1 parent 44326fe commit 29d7166

7 files changed

Lines changed: 22 additions & 33 deletions

File tree

sphinx/builders/gettext.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
from codecs import open
6-
from collections import OrderedDict, defaultdict
6+
from collections import defaultdict
77
from datetime import datetime, timedelta, tzinfo
88
from os import getenv, path, walk
99
from time import time
@@ -43,10 +43,10 @@ class Catalog:
4343
"""Catalog of translatable messages."""
4444

4545
def __init__(self) -> None:
46-
self.messages: list[str] = [] # retain insertion order, a la OrderedDict
46+
self.messages: list[str] = [] # retain insertion order
4747

4848
# msgid -> file, line, uid
49-
self.metadata: dict[str, list[tuple[str, int, str]]] = OrderedDict()
49+
self.metadata: dict[str, list[tuple[str, int, str]]] = {}
5050

5151
def add(self, msg: str, origin: Element | MsgOrigin) -> None:
5252
if not hasattr(origin, 'uid'):

sphinx/cmd/quickstart.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import os
88
import sys
99
import time
10-
from collections import OrderedDict
1110
from os import path
1211
from typing import TYPE_CHECKING, Any, Callable
1312

@@ -36,18 +35,18 @@
3635
from sphinx.util.osutil import ensuredir
3736
from sphinx.util.template import SphinxRenderer
3837

39-
EXTENSIONS = OrderedDict([
40-
('autodoc', __('automatically insert docstrings from modules')),
41-
('doctest', __('automatically test code snippets in doctest blocks')),
42-
('intersphinx', __('link between Sphinx documentation of different projects')),
43-
('todo', __('write "todo" entries that can be shown or hidden on build')),
44-
('coverage', __('checks for documentation coverage')),
45-
('imgmath', __('include math, rendered as PNG or SVG images')),
46-
('mathjax', __('include math, rendered in the browser by MathJax')),
47-
('ifconfig', __('conditional inclusion of content based on config values')),
48-
('viewcode', __('include links to the source code of documented Python objects')),
49-
('githubpages', __('create .nojekyll file to publish the document on GitHub pages')),
50-
])
38+
EXTENSIONS = {
39+
'autodoc': __('automatically insert docstrings from modules'),
40+
'doctest': __('automatically test code snippets in doctest blocks'),
41+
'intersphinx': __('link between Sphinx documentation of different projects'),
42+
'todo': __('write "todo" entries that can be shown or hidden on build'),
43+
'coverage': __('checks for documentation coverage'),
44+
'imgmath': __('include math, rendered as PNG or SVG images'),
45+
'mathjax': __('include math, rendered in the browser by MathJax'),
46+
'ifconfig': __('conditional inclusion of content based on config values'),
47+
'viewcode': __('include links to the source code of documented Python objects'),
48+
'githubpages': __('create .nojekyll file to publish the document on GitHub pages'),
49+
}
5150

5251
DEFAULTS = {
5352
'path': '.',

sphinx/config.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import re
66
import traceback
77
import types
8-
from collections import OrderedDict
98
from os import getenv, path
109
from typing import TYPE_CHECKING, Any, Callable, Generator, Iterator, NamedTuple
1110

@@ -382,14 +381,11 @@ def convert_source_suffix(app: Sphinx, config: Config) -> None:
382381
#
383382
# The default filetype is determined on later step.
384383
# By default, it is considered as restructuredtext.
385-
config.source_suffix = OrderedDict({source_suffix: None}) # type: ignore
384+
config.source_suffix = {source_suffix: None} # type: ignore[attr-defined]
386385
elif isinstance(source_suffix, (list, tuple)):
387386
# if list, considers as all of them are default filetype
388-
config.source_suffix = OrderedDict([(s, None) for s in source_suffix]) # type: ignore
389-
elif isinstance(source_suffix, dict):
390-
# if dict, convert it to OrderedDict
391-
config.source_suffix = OrderedDict(config.source_suffix) # type: ignore
392-
else:
387+
config.source_suffix = {s: None for s in source_suffix} # type: ignore[attr-defined]
388+
elif not isinstance(source_suffix, dict):
393389
logger.warning(__("The config value `source_suffix' expects "
394390
"a string, list of strings, or dictionary. "
395391
"But `%r' is given." % source_suffix))

sphinx/ext/autodoc/typehints.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
import re
6-
from collections import OrderedDict
76
from typing import Any, Iterable, cast
87

98
from docutils import nodes
@@ -27,7 +26,7 @@ def record_typehints(app: Sphinx, objtype: str, name: str, obj: Any,
2726
try:
2827
if callable(obj):
2928
annotations = app.env.temp_data.setdefault('annotations', {})
30-
annotation = annotations.setdefault(name, OrderedDict())
29+
annotation = annotations.setdefault(name, {})
3130
sig = inspect.signature(obj, type_aliases=app.config.autodoc_type_aliases)
3231
for param in sig.parameters.values():
3332
if param.annotation is not param.empty:

sphinx/pycode/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
import tokenize
6-
from collections import OrderedDict
76
from importlib import import_module
87
from os import path
98
from typing import TYPE_CHECKING, Any
@@ -125,7 +124,7 @@ def analyze(self) -> None:
125124
parser = Parser(self.code)
126125
parser.parse()
127126

128-
self.attr_docs = OrderedDict()
127+
self.attr_docs = {}
129128
for (scope, comment) in parser.comments.items():
130129
if comment:
131130
self.attr_docs[scope] = comment.splitlines() + ['']

sphinx/pycode/parser.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import itertools
88
import re
99
import tokenize
10-
from collections import OrderedDict
1110
from inspect import Signature
1211
from token import DEDENT, INDENT, NAME, NEWLINE, NUMBER, OP, STRING
1312
from tokenize import COMMENT, NL
@@ -221,7 +220,7 @@ def __init__(self, buffers: list[str], encoding: str) -> None:
221220
self.context: list[str] = []
222221
self.current_classes: list[str] = []
223222
self.current_function: ast.FunctionDef | None = None
224-
self.comments: dict[tuple[str, str], str] = OrderedDict()
223+
self.comments: dict[tuple[str, str], str] = {}
225224
self.annotations: dict[tuple[str, str], str] = {}
226225
self.previous: ast.AST | None = None
227226
self.deforders: dict[str, int] = {}

tests/test_project.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Tests project module."""
22

3-
from collections import OrderedDict
4-
53
import pytest
64

75
from sphinx.project import Project
@@ -55,8 +53,7 @@ def test_project_path2doc(app):
5553

5654
@pytest.mark.sphinx(srcdir='project_doc2path', testroot='basic')
5755
def test_project_doc2path(app):
58-
source_suffix = OrderedDict([('.rst', 'restructuredtext'),
59-
('.txt', 'restructuredtext')])
56+
source_suffix = {'.rst': 'restructuredtext', '.txt': 'restructuredtext'}
6057

6158
project = Project(app.srcdir, source_suffix)
6259
assert project.doc2path('index') == (app.srcdir / 'index.rst')

0 commit comments

Comments
 (0)