Skip to content

Commit 83560ba

Browse files
committed
Drop Python <=3.7 syntax
Closes #449
1 parent 1aade0f commit 83560ba

File tree

47 files changed

+68
-111
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+68
-111
lines changed

autoapi/_astroid_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def get_full_basenames(node):
119119
def _get_const_value(node):
120120
if isinstance(node, astroid.nodes.Const):
121121
if isinstance(node.value, str) and "\n" in node.value:
122-
return '"""{0}"""'.format(node.value)
122+
return f'"""{node.value}"""'
123123

124124
class NotConstException(Exception):
125125
pass

autoapi/_mapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ def read_file(self, path, **kwargs):
434434
else:
435435
parsed_data = Parser().parse_file(path)
436436
return parsed_data
437-
except (IOError, TypeError, ImportError):
437+
except (OSError, TypeError, ImportError):
438438
LOGGER.debug("Reason:", exc_info=True)
439439
LOGGER.warning(
440440
f"Unable to read file: {path}",

autoapi/_objects.py

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

33
import functools
44
import pathlib
5-
from typing import List, Optional, Tuple
65

76
import sphinx
87
import sphinx.util
@@ -66,7 +65,7 @@ def __init__(
6665
This is the same as the fully qualified name of the object.
6766
"""
6867

69-
self.children: List[PythonObject] = []
68+
self.children: list[PythonObject] = []
7069
"""The members of this object.
7170
7271
For example, the classes and functions defined in the parent module.
@@ -79,7 +78,7 @@ def __init__(
7978

8079
# For later
8180
self._class_content = class_content
82-
self._display_cache: Optional[bool] = None
81+
self._display_cache: bool | None = None
8382

8483
def __getstate__(self):
8584
"""Obtains serialisable data for pickling."""
@@ -248,7 +247,7 @@ def _ask_ignore(self, skip: bool) -> bool:
248247

249248
return ask_result if ask_result is not None else skip
250249

251-
def _children_of_type(self, type_: str) -> List[PythonObject]:
250+
def _children_of_type(self, type_: str) -> list[PythonObject]:
252251
return list(child for child in self.children if child.type == type_)
253252

254253

@@ -268,20 +267,20 @@ def __init__(self, *args, **kwargs):
268267
self.args: str = _format_args(self.obj["args"], show_annotations)
269268
"""The arguments to this object, formatted as a string."""
270269

271-
self.return_annotation: Optional[str] = (
270+
self.return_annotation: str | None = (
272271
self.obj["return_annotation"] if show_annotations else None
273272
)
274273
"""The type annotation for the return type of this function.
275274
276275
This will be ``None`` if an annotation
277276
or annotation comment was not given.
278277
"""
279-
self.properties: List[str] = self.obj["properties"]
278+
self.properties: list[str] = self.obj["properties"]
280279
"""The properties that describe what type of function this is.
281280
282281
Can be only be: async.
283282
"""
284-
self.overloads: List[Tuple[str, str]] = [
283+
self.overloads: list[tuple[str, str]] = [
285284
(_format_args(args), return_annotation)
286285
for args, return_annotation in self.obj["overloads"]
287286
]
@@ -300,7 +299,7 @@ class PythonMethod(PythonFunction):
300299
def __init__(self, *args, **kwargs):
301300
super().__init__(*args, **kwargs)
302301

303-
self.properties: List[str] = self.obj["properties"]
302+
self.properties: list[str] = self.obj["properties"]
304303
"""The properties that describe what type of method this is.
305304
306305
Can be any of: abstractmethod, async, classmethod, property, staticmethod.
@@ -322,9 +321,9 @@ class PythonProperty(PythonObject):
322321
def __init__(self, *args, **kwargs):
323322
super().__init__(*args, **kwargs)
324323

325-
self.annotation: Optional[str] = self.obj["return_annotation"]
324+
self.annotation: str | None = self.obj["return_annotation"]
326325
"""The type annotation of this property."""
327-
self.properties: List[str] = self.obj["properties"]
326+
self.properties: list[str] = self.obj["properties"]
328327
"""The properties that describe what type of property this is.
329328
330329
Can be any of: abstractmethod, classmethod.
@@ -340,12 +339,12 @@ class PythonData(PythonObject):
340339
def __init__(self, *args, **kwargs):
341340
super().__init__(*args, **kwargs)
342341

343-
self.value: Optional[str] = self.obj.get("value")
342+
self.value: str | None = self.obj.get("value")
344343
"""The value of this attribute.
345344
346345
This will be ``None`` if the value is not constant.
347346
"""
348-
self.annotation: Optional[str] = self.obj.get("annotation")
347+
self.annotation: str | None = self.obj.get("annotation")
349348
"""The type annotation of this attribute.
350349
351350
This will be ``None`` if an annotation
@@ -424,7 +423,7 @@ class PythonClass(PythonObject):
424423
def __init__(self, *args, **kwargs):
425424
super().__init__(*args, **kwargs)
426425

427-
self.bases: List[str] = self.obj["bases"]
426+
self.bases: list[str] = self.obj["bases"]
428427
"""The fully qualified names of all base classes."""
429428

430429
self._docstring_resolved: bool = False
@@ -447,7 +446,7 @@ def args(self) -> str:
447446
return args
448447

449448
@property
450-
def overloads(self) -> List[Tuple[str, str]]:
449+
def overloads(self) -> list[tuple[str, str]]:
451450
overloads = []
452451

453452
if self.constructor:
@@ -503,7 +502,7 @@ def classes(self):
503502
return self._children_of_type("class")
504503

505504
@property
506-
@functools.lru_cache()
505+
@functools.lru_cache
507506
def constructor(self):
508507
for child in self.children:
509508
if child.short_name == "__init__":

autoapi/documenters.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ def get_doc(self, encoding=None, ignore=1):
6161

6262
def process_doc(self, docstrings):
6363
for docstring in docstrings:
64-
for line in docstring:
65-
yield line
64+
yield from docstring
6665

6766
yield ""
6867

autoapi/extension.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
This extension allows you to automagically generate API documentation from your project.
44
"""
55

6-
import io
76
import os
87
import shutil
98
from typing import Dict, Tuple
@@ -228,10 +227,7 @@ def viewcode_find(app, modname):
228227
children = getattr(obj, "children", ())
229228
stack.extend((full_name + ".", gchild) for gchild in children)
230229

231-
if module.obj["encoding"]:
232-
stream = io.open(module.obj["file_path"], encoding=module.obj["encoding"])
233-
else:
234-
stream = open(module.obj["file_path"], encoding="utf-8")
230+
stream = open(module.obj["file_path"], encoding=module.obj.get("encoding", "utf-8"))
235231

236232
with stream as in_f:
237233
source = in_f.read()

docs/changes/449.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Drop Python <=3.7 syntax

tests/python/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def build(test_dir, **kwargs):
4141
suppress.append("app.add_directive")
4242
suppress.append("app.add_role")
4343

44-
os.chdir("tests/python/{0}".format(test_dir))
44+
os.chdir(f"tests/python/{test_dir}")
4545
rebuild(**kwargs)
4646

4747
yield build
@@ -60,7 +60,7 @@ def parse():
6060

6161
def parser(path):
6262
if path not in cache:
63-
with io.open(path, encoding="utf8") as file_handle:
63+
with open(path, encoding="utf8") as file_handle:
6464
cache[path] = BeautifulSoup(file_handle, features="html.parser")
6565

6666
return cache[path]

tests/python/pep695/conf.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
templates_path = ["_templates"]
42
source_suffix = ".rst"
53
master_doc = "index"

tests/python/py310unionpipe/conf.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
templates_path = ["_templates"]
42
source_suffix = ".rst"
53
master_doc = "index"

tests/python/py38positionalparams/conf.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
templates_path = ["_templates"]
42
source_suffix = ".rst"
53
master_doc = "index"

0 commit comments

Comments
 (0)