Skip to content

Commit 2a589c0

Browse files
authored
Prefer sys.version_info for feature checks (#11736)
1 parent 868199e commit 2a589c0

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

sphinx/cmd/make_mode.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
)
2626
from sphinx.util.osutil import rmtree
2727

28-
try:
29-
from contextlib import chdir # type: ignore[attr-defined]
30-
except ImportError:
28+
if sys.version_info >= (3, 11):
29+
from contextlib import chdir
30+
else:
3131
from sphinx.util.osutil import _chdir as chdir
3232

3333
if TYPE_CHECKING:

sphinx/config.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import sys
56
import time
67
import traceback
78
import types
@@ -14,9 +15,9 @@
1415
from sphinx.util.osutil import fs_encoding
1516
from sphinx.util.typing import NoneType
1617

17-
try:
18-
from contextlib import chdir # type: ignore[attr-defined]
19-
except ImportError:
18+
if sys.version_info >= (3, 11):
19+
from contextlib import chdir
20+
else:
2021
from sphinx.util.osutil import _chdir as chdir
2122

2223
if TYPE_CHECKING:

sphinx/util/typing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
if TYPE_CHECKING:
1616
import enum
1717

18-
try:
19-
from types import UnionType # type: ignore[attr-defined] # python 3.10 or above
20-
except ImportError:
18+
if sys.version_info >= (3, 10):
19+
from types import UnionType
20+
else:
2121
UnionType = None
2222

2323
# classes that have incorrect __module__

0 commit comments

Comments
 (0)