Skip to content

Commit fab8994

Browse files
committed
style: Format (unsafe fixes)
1 parent 417eb1b commit fab8994

File tree

17 files changed

+107
-112
lines changed

17 files changed

+107
-112
lines changed

scripts/gen_credits.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from itertools import chain
1111
from pathlib import Path
1212
from textwrap import dedent
13-
from typing import Dict, Union
13+
from typing import Union
1414

1515
from jinja2 import StrictUndefined
1616
from jinja2.sandbox import SandboxedEnvironment
@@ -29,8 +29,8 @@
2929
project_name = project["name"]
3030
devdeps = [dep for group in pyproject["dependency-groups"].values() for dep in group if not dep.startswith("-e")]
3131

32-
PackageMetadata = Dict[str, Union[str, Iterable[str]]]
33-
Metadata = Dict[str, PackageMetadata]
32+
PackageMetadata = dict[str, Union[str, Iterable[str]]]
33+
Metadata = dict[str, PackageMetadata]
3434

3535

3636
def _merge_fields(metadata: dict) -> PackageMetadata:

scripts/get_annotations.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import sys
88
from multiprocessing import Pool, cpu_count
99
from pathlib import Path
10-
from typing import List
1110

1211
try:
1312
from ast import unparse # type: ignore[attr-defined]
@@ -52,7 +51,7 @@ def scan_file(filepath: str) -> set:
5251
return annotations
5352

5453

55-
def main(directories: List[str]) -> int:
54+
def main(directories: list[str]) -> int:
5655
"""Scan Python files in a list of directories.
5756
5857
First, all the files are stored in a list,

src/pytkdocs/cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import json
1818
import sys
1919
import traceback
20-
from collections.abc import Iterator
2120
from contextlib import contextmanager
2221
from io import StringIO
2322
from typing import TYPE_CHECKING, Any
@@ -27,6 +26,8 @@
2726
from pytkdocs.serializer import serialize_object
2827

2928
if TYPE_CHECKING:
29+
from collections.abc import Iterator
30+
3031
from pytkdocs.objects import Object
3132

3233

src/pytkdocs/loader.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from itertools import chain
1515
from operator import attrgetter
1616
from pathlib import Path
17-
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union
17+
from typing import Any, Callable, Optional, Union
1818

1919
from pytkdocs.objects import Attribute, Class, Function, Method, Module, Object, Source
2020
from pytkdocs.parsers.attributes import get_class_attributes, get_instance_attributes, get_module_attributes, merge
@@ -223,7 +223,7 @@ def get_object_tree(path: str, new_path_syntax: bool = False) -> ObjectNode: #
223223
if not path:
224224
raise ValueError(f"path must be a valid Python path, not {path}")
225225

226-
objects: List[str] = []
226+
objects: list[str] = []
227227

228228
if ":" in path or new_path_syntax:
229229
try:
@@ -293,7 +293,7 @@ class Loader:
293293

294294
def __init__(
295295
self,
296-
filters: Optional[List[str]] = None,
296+
filters: Optional[list[str]] = None,
297297
docstring_style: str = "google",
298298
docstring_options: Optional[dict] = None,
299299
inherited_members: bool = False, # noqa: FBT001, FBT002
@@ -313,11 +313,11 @@ def __init__(
313313

314314
self.filters = [(filtr, re.compile(filtr.lstrip("!"))) for filtr in filters]
315315
self.docstring_parser = PARSERS[docstring_style](**(docstring_options or {}))
316-
self.errors: List[str] = []
316+
self.errors: list[str] = []
317317
self.select_inherited_members = inherited_members
318318
self.new_path_syntax = new_path_syntax
319319

320-
def get_object_documentation(self, dotted_path: str, members: Optional[Union[Set[str], bool]] = None) -> Object:
320+
def get_object_documentation(self, dotted_path: str, members: Optional[Union[set[str], bool]] = None) -> Object:
321321
"""Get the documentation for an object and its children.
322322
323323
Arguments:
@@ -359,7 +359,7 @@ def get_object_documentation(self, dotted_path: str, members: Optional[Union[Set
359359
def get_module_documentation(
360360
self,
361361
node: ObjectNode,
362-
select_members: Optional[Union[Set[str], bool]] = None,
362+
select_members: Optional[Union[set[str], bool]] = None,
363363
) -> Module:
364364
"""Get the documentation for a module and its children.
365365
@@ -430,7 +430,7 @@ def _class_path(cls: type) -> str: # noqa: PLW0211
430430
def get_class_documentation(
431431
self,
432432
node: ObjectNode,
433-
select_members: Optional[Union[Set[str], bool]] = None,
433+
select_members: Optional[Union[set[str], bool]] = None,
434434
) -> Class:
435435
"""Get the documentation for a class and its children.
436436
@@ -462,10 +462,10 @@ def get_class_documentation(
462462
)
463463

464464
# Even if we don't select members, we want to correctly parse the docstring
465-
attributes_data: Dict[str, Dict[str, Any]] = {}
465+
attributes_data: dict[str, dict[str, Any]] = {}
466466
for parent_class in reversed(class_.__mro__[:-1]):
467467
merge(attributes_data, get_class_attributes(parent_class))
468-
context: Dict[str, Any] = {"attributes": attributes_data}
468+
context: dict[str, Any] = {"attributes": attributes_data}
469469
if "__init__" in class_.__dict__:
470470
try:
471471
attributes_data.update(get_instance_attributes(class_.__init__))
@@ -567,7 +567,7 @@ def add_fields(
567567
root_object: Object,
568568
attr_name: str,
569569
members: Mapping[str, Any],
570-
select_members: Optional[Union[Set[str], bool]],
570+
select_members: Optional[Union[set[str], bool]],
571571
base_class: type,
572572
add_method: Callable,
573573
) -> None:
@@ -615,7 +615,7 @@ def get_function_documentation(self, node: ObjectNode) -> Function:
615615
except OSError:
616616
source = None
617617

618-
properties: List[str] = []
618+
properties: list[str] = []
619619
if node.is_coroutine_function():
620620
properties.append("async")
621621

@@ -833,7 +833,7 @@ def get_regular_method_documentation(self, node: ObjectNode) -> Method:
833833
break
834834
return method
835835

836-
def get_method_documentation(self, node: ObjectNode, properties: Optional[List[str]] = None) -> Method:
836+
def get_method_documentation(self, node: ObjectNode, properties: Optional[list[str]] = None) -> Method:
837837
"""Get the documentation for a method or method descriptor.
838838
839839
Arguments:
@@ -905,7 +905,7 @@ def get_attribute_documentation(node: ObjectNode, attribute_data: Optional[dict]
905905
attr_type=attribute_data.get("annotation", None),
906906
)
907907

908-
def select(self, name: str, names: Set[str]) -> bool:
908+
def select(self, name: str, names: set[str]) -> bool:
909909
"""Tells whether we should select an object or not, given its name.
910910
911911
If the set of names is not empty, we check against it, otherwise we check against filters.
@@ -963,7 +963,7 @@ def field_is_inherited(field_name: str, fields_name: str, base_class: type) -> b
963963
)
964964

965965

966-
def split_attr_name(attr_name: str) -> Tuple[str, Optional[str]]:
966+
def split_attr_name(attr_name: str) -> tuple[str, Optional[str]]:
967967
"""Split an attribute name into a first-order attribute name and remainder.
968968
969969
Args:
@@ -985,7 +985,7 @@ def get_fields( # noqa: D103
985985
*,
986986
members: Optional[Mapping[str, Any]] = None,
987987
class_obj: Optional[type] = None,
988-
) -> Dict[str, Any]:
988+
) -> dict[str, Any]:
989989
if not (bool(members) ^ bool(class_obj)):
990990
raise ValueError("Either members or class_obj is required.")
991991
first_order_attr_name, remainder = split_attr_name(attr_name)

src/pytkdocs/objects.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from abc import ABCMeta
2020
from functools import lru_cache
2121
from pathlib import Path
22-
from typing import Any, List, Optional, Union
22+
from typing import Any, Optional, Union
2323

2424
from pytkdocs.parsers.docstrings.base import Parser, Section
2525
from pytkdocs.properties import NAME_CLASS_PRIVATE, NAME_PRIVATE, NAME_SPECIAL, ApplicableNameProperty
@@ -32,7 +32,7 @@ class Source:
3232
[`inspect.getsourceslines`](https://docs.python.org/3/library/inspect.html#inspect.getsourcelines).
3333
"""
3434

35-
def __init__(self, lines: Union[str, List[str]], line_start: int) -> None:
35+
def __init__(self, lines: Union[str, list[str]], line_start: int) -> None:
3636
"""Initialize the object.
3737
3838
Arguments:
@@ -52,7 +52,7 @@ class Object(metaclass=ABCMeta): # noqa: B024
5252
Each instance additionally stores references to its children, grouped by category.
5353
"""
5454

55-
possible_name_properties: List[ApplicableNameProperty] = [] # noqa: RUF012
55+
possible_name_properties: list[ApplicableNameProperty] = [] # noqa: RUF012
5656
"""
5757
The properties that we can apply to the object based on its name.
5858
@@ -65,7 +65,7 @@ def __init__(
6565
path: str,
6666
file_path: str,
6767
docstring: Optional[str] = "",
68-
properties: Optional[List[str]] = None,
68+
properties: Optional[list[str]] = None,
6969
source: Optional[Source] = None,
7070
) -> None:
7171
"""Initialize the object.
@@ -86,9 +86,9 @@ def __init__(
8686
"""The file path of the object's direct parent module."""
8787
self.docstring = docstring
8888
"""The object's docstring."""
89-
self.docstring_sections: List[Section] = []
89+
self.docstring_sections: list[Section] = []
9090
"""The object's docstring parsed into sections."""
91-
self.docstring_errors: List[str] = []
91+
self.docstring_errors: list[str] = []
9292
"""The errors detected while parsing the docstring."""
9393
self.properties = properties or []
9494
"""The object's properties."""
@@ -100,17 +100,17 @@ def __init__(
100100
self._path_map = {self.path: self}
101101
self._parsed = False
102102

103-
self.attributes: List[Attribute] = []
103+
self.attributes: list[Attribute] = []
104104
"""The list of all the object's attributes."""
105-
self.methods: List[Method] = []
105+
self.methods: list[Method] = []
106106
"""The list of all the object's methods."""
107-
self.functions: List[Function] = []
107+
self.functions: list[Function] = []
108108
"""The list of all the object's functions."""
109-
self.modules: List[Module] = []
109+
self.modules: list[Module] = []
110110
"""The list of all the object's submodules."""
111-
self.classes: List[Class] = []
111+
self.classes: list[Class] = []
112112
"""The list of all the object's classes."""
113-
self.children: List[Object] = []
113+
self.children: list[Object] = []
114114
"""The list of all the object's children."""
115115

116116
def __str__(self) -> str:
@@ -193,7 +193,7 @@ def name_to_check(self) -> str:
193193
return self.name
194194

195195
@property
196-
def name_properties(self) -> List[str]:
196+
def name_properties(self) -> list[str]:
197197
"""Return the object's name properties.
198198
199199
Returns:
@@ -253,7 +253,7 @@ def add_child(self, obj: "Object") -> None:
253253

254254
self._path_map[obj.path] = obj
255255

256-
def add_children(self, children: List["Object"]) -> None:
256+
def add_children(self, children: list["Object"]) -> None:
257257
"""Add a list of objects as children of this object.
258258
259259
Arguments:
@@ -309,7 +309,7 @@ def has_contents(self) -> bool:
309309
class Module(Object):
310310
"""A class to store information about a module."""
311311

312-
possible_name_properties: List[ApplicableNameProperty] = [NAME_SPECIAL, NAME_PRIVATE] # noqa: RUF012
312+
possible_name_properties: list[ApplicableNameProperty] = [NAME_SPECIAL, NAME_PRIVATE] # noqa: RUF012
313313

314314
@property
315315
def file_name(self) -> str:
@@ -328,9 +328,9 @@ def name_to_check(self) -> str: # noqa: D102
328328
class Class(Object):
329329
"""A class to store information about a class."""
330330

331-
possible_name_properties: List[ApplicableNameProperty] = [NAME_PRIVATE] # noqa: RUF012
331+
possible_name_properties: list[ApplicableNameProperty] = [NAME_PRIVATE] # noqa: RUF012
332332

333-
def __init__(self, *args: Any, bases: Optional[List[str]] = None, **kwargs: Any):
333+
def __init__(self, *args: Any, bases: Optional[list[str]] = None, **kwargs: Any):
334334
"""Initialize the object.
335335
336336
Arguments:
@@ -348,7 +348,7 @@ class Function(Object):
348348
It accepts an additional `signature` argument at instantiation.
349349
"""
350350

351-
possible_name_properties: List[ApplicableNameProperty] = [NAME_PRIVATE] # noqa: RUF012
351+
possible_name_properties: list[ApplicableNameProperty] = [NAME_PRIVATE] # noqa: RUF012
352352

353353
def __init__(self, *args: Any, signature: Optional[inspect.Signature] = None, **kwargs: Any):
354354
"""Initialize the object.
@@ -368,7 +368,7 @@ class Method(Object):
368368
It accepts an additional `signature` argument at instantiation.
369369
"""
370370

371-
possible_name_properties: List[ApplicableNameProperty] = [NAME_SPECIAL, NAME_PRIVATE] # noqa: RUF012
371+
possible_name_properties: list[ApplicableNameProperty] = [NAME_SPECIAL, NAME_PRIVATE] # noqa: RUF012
372372

373373
def __init__(self, *args: Any, signature: Optional[inspect.Signature] = None, **kwargs: Any):
374374
"""Initialize the object.
@@ -388,7 +388,7 @@ class Attribute(Object):
388388
It accepts an additional `attr_type` argument at instantiation.
389389
"""
390390

391-
possible_name_properties: List[ApplicableNameProperty] = [NAME_SPECIAL, NAME_CLASS_PRIVATE, NAME_PRIVATE] # noqa: RUF012
391+
possible_name_properties: list[ApplicableNameProperty] = [NAME_SPECIAL, NAME_CLASS_PRIVATE, NAME_PRIVATE] # noqa: RUF012
392392

393393
def __init__(self, *args: Any, attr_type: Optional[Any] = None, **kwargs: Any):
394394
"""Initialize the object.

src/pytkdocs/parsers/attributes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from functools import lru_cache
77
from textwrap import dedent
88
from types import ModuleType
9-
from typing import Any, Callable, List, get_type_hints
9+
from typing import Any, Callable, get_type_hints
1010

1111
try:
1212
from ast import unparse # type: ignore[attr-defined]
@@ -16,7 +16,7 @@
1616
RECURSIVE_NODES = (ast.If, ast.IfExp, ast.Try, ast.With)
1717

1818

19-
def get_nodes(obj: Any) -> List[ast.stmt]: # noqa: D103
19+
def get_nodes(obj: Any) -> list[ast.stmt]: # noqa: D103
2020
try:
2121
source = inspect.getsource(obj)
2222
except (OSError, TypeError):

src/pytkdocs/parsers/docstrings/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""The parsers' package."""
22

3-
from typing import Dict, Type
4-
53
from pytkdocs.parsers.docstrings.base import Parser, UnavailableParser
64
from pytkdocs.parsers.docstrings.google import Google
75
from pytkdocs.parsers.docstrings.markdown import Markdown
@@ -15,7 +13,7 @@
1513
)
1614

1715

18-
PARSERS: Dict[str, Type[Parser]] = {
16+
PARSERS: dict[str, type[Parser]] = {
1917
"google": Google,
2018
"restructured-text": RestructuredText,
2119
"numpy": Numpy,

src/pytkdocs/parsers/docstrings/base.py

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

33
import inspect
44
from abc import ABCMeta, abstractmethod
5-
from typing import Any, List, Optional, Tuple
5+
from typing import Any, Optional
66

77
empty = inspect.Signature.empty
88

@@ -137,9 +137,9 @@ class Parser(metaclass=ABCMeta):
137137
def __init__(self, **kwargs: Any) -> None: # noqa: ARG002
138138
"""Initialize the object."""
139139
self.context: dict = {}
140-
self.errors: List[str] = []
140+
self.errors: list[str] = []
141141

142-
def parse(self, docstring: str, context: Optional[dict] = None) -> Tuple[List[Section], List[str]]:
142+
def parse(self, docstring: str, context: Optional[dict] = None) -> tuple[list[Section], list[str]]:
143143
"""Parse a docstring and return a list of sections and parsing errors.
144144
145145
Arguments:
@@ -166,7 +166,7 @@ def error(self, message: str) -> None:
166166
self.errors.append(message)
167167

168168
@abstractmethod
169-
def parse_sections(self, docstring: str) -> List[Section]:
169+
def parse_sections(self, docstring: str) -> list[Section]:
170170
"""Parse a docstring as a list of sections.
171171
172172
Arguments:
@@ -182,7 +182,7 @@ class UnavailableParser: # noqa: D101
182182
def __init__(self, message: str) -> None: # noqa: D107
183183
self.message = message
184184

185-
def parse(self, docstring: str, context: Optional[dict] = None) -> Tuple[List[Section], List[str]]: # noqa: ARG002, D102
185+
def parse(self, docstring: str, context: Optional[dict] = None) -> tuple[list[Section], list[str]]: # noqa: ARG002, D102
186186
context = context or {}
187187
message = self.message
188188
if "obj" in context:

0 commit comments

Comments
 (0)