generated from jCloud/repository-template
chore: lint source code using Ruff
This commit is contained in:
35 files changed
+161
-130
No files matched your search
@@ -12,9 +12,9 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from . import namespaces
|
||||
from ._core import *
|
||||
from ._core import __all__ as _core__all__
|
||||
from . import namespaces
|
||||
|
||||
__all__ = [
|
||||
*_core__all__,
|
||||
|
||||
@@ -13,25 +13,26 @@
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import annotations
|
||||
from ...utils import non_empty_str, get_relative_path_segments
|
||||
from ...exceptions import PythonArgumentStructureError, InvalidNamespaceError
|
||||
from .namespaces import PythonModuleNamespace, PythonPackageNamespace
|
||||
|
||||
import ast
|
||||
import pathlib
|
||||
from collections.abc import Iterator
|
||||
from dataclasses import dataclass
|
||||
from typing import TypeAlias
|
||||
|
||||
import docstring_parser
|
||||
|
||||
from ...exceptions import InvalidNamespaceError, PythonArgumentStructureError
|
||||
from ...utils import get_relative_path_segments, non_empty_str
|
||||
from .arguments import PythonArgumentKind, PythonFunctionArgument
|
||||
from .definitions import (
|
||||
PythonAsyncFunctionDefinition,
|
||||
PythonClassDefinition,
|
||||
PythonDefinition,
|
||||
PythonFunctionDefinition,
|
||||
)
|
||||
from .arguments import PythonArgumentKind, PythonFunctionArgument
|
||||
from .docstrings import PythonDocstring
|
||||
from collections.abc import Iterator
|
||||
from typing import TypeAlias, Union
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
import docstring_parser
|
||||
import pathlib
|
||||
import ast
|
||||
import types
|
||||
from .namespaces import PythonModuleNamespace, PythonPackageNamespace
|
||||
|
||||
__all__ = [
|
||||
'PythonDefinitionDocumentationIncludeSections',
|
||||
@@ -63,9 +64,9 @@ def _collect_definitions(tree_or_node) -> Iterator[PythonDefinition]:
|
||||
_Arguments: TypeAlias = tuple[
|
||||
list[PythonFunctionArgument],
|
||||
list[PythonFunctionArgument],
|
||||
Union[PythonFunctionArgument, None],
|
||||
PythonFunctionArgument | None,
|
||||
list[PythonFunctionArgument],
|
||||
Union[PythonFunctionArgument, None],
|
||||
PythonFunctionArgument | None,
|
||||
]
|
||||
|
||||
|
||||
@@ -298,12 +299,12 @@ def _markdown_table(
|
||||
return table.strip()
|
||||
|
||||
|
||||
def _is_docstring(docstring: Union[str, PythonDocstring, None]) -> bool:
|
||||
def _is_docstring(docstring: str | PythonDocstring | None) -> bool:
|
||||
"""
|
||||
Checks whether the docstring is a docstring or an empty docstring.
|
||||
|
||||
:param docstring: The docstring.
|
||||
:type docstring: Union[str, PythonDocstring, None]
|
||||
:type docstring: str | PythonDocstring | None
|
||||
|
||||
:return: Whether there is a docstring.
|
||||
:rtype: bool
|
||||
@@ -320,8 +321,8 @@ def _is_docstring(docstring: Union[str, PythonDocstring, None]) -> bool:
|
||||
|
||||
@dataclass
|
||||
class _FunctionParamInfo:
|
||||
annotation: Union[str, None]
|
||||
description: Union[str, None]
|
||||
annotation: str | None
|
||||
description: str | None
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -908,7 +909,7 @@ class PythonModuleDocumentationGenerator:
|
||||
:param src_directory: The directory of the source code. It is
|
||||
optional and only used for making the module
|
||||
identifiers in the documentation relative.
|
||||
:type src_directory: Union[pathlib.Path, None]
|
||||
:type src_directory: pathlib.Path | None
|
||||
:param include_sections: The sections that will be included.
|
||||
:type include_sections: PythonDefinitionDocumentationIncludeSections
|
||||
:param kwargs: The options for ``PythonDefinitionDocumentationGenerator``.
|
||||
@@ -917,7 +918,7 @@ class PythonModuleDocumentationGenerator:
|
||||
def __init__(
|
||||
self,
|
||||
module_path: pathlib.Path,
|
||||
src_directory: Union[pathlib.Path, None] = None,
|
||||
src_directory: pathlib.Path | None = None,
|
||||
include_sections: PythonDefinitionDocumentationIncludeSections = (
|
||||
PythonDefinitionDocumentationIncludeSections()
|
||||
),
|
||||
|
||||
@@ -13,17 +13,18 @@
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import annotations
|
||||
from enum import Enum
|
||||
from typing import Union
|
||||
|
||||
import ast
|
||||
from ...utils import assert_that_is_instance
|
||||
import keyword
|
||||
import types
|
||||
from enum import Enum
|
||||
|
||||
from ...exceptions import (
|
||||
InvalidPythonAnnotationError,
|
||||
InvalidPythonIdentifierError,
|
||||
PythonArgumentStructureError,
|
||||
)
|
||||
import keyword
|
||||
import types
|
||||
from ...utils import assert_that_is_instance
|
||||
|
||||
__all__ = [
|
||||
'PythonArgumentKind',
|
||||
@@ -49,17 +50,17 @@ class PythonFunctionArgument:
|
||||
:param kind: The kind of the argument.
|
||||
:type kind: ArgumentKind
|
||||
:param default: The default value of the argument.
|
||||
:type default: Union[str, None]
|
||||
:type default: str | None
|
||||
:param annotation: The type annotation of the argument.
|
||||
:type annotation: Union[str, None]
|
||||
:type annotation: str | None
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
kind: PythonArgumentKind,
|
||||
default: Union[str, None],
|
||||
annotation: Union[str, None],
|
||||
default: str | None,
|
||||
annotation: str | None,
|
||||
) -> None:
|
||||
assert_that_is_instance(name, str)
|
||||
assert_that_is_instance(kind, PythonArgumentKind)
|
||||
|
||||
@@ -13,14 +13,15 @@
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import annotations
|
||||
from typing import Union
|
||||
|
||||
import ast
|
||||
from .arguments import PythonFunctionArgument, PythonASTArgumentsListParser
|
||||
from .docstrings import PythonDocstring
|
||||
import keyword
|
||||
import types
|
||||
|
||||
from ...exceptions import InvalidPythonIdentifierError
|
||||
from ...utils import assert_that_is_instance
|
||||
import types
|
||||
from .arguments import PythonASTArgumentsListParser, PythonFunctionArgument
|
||||
from .docstrings import PythonDocstring
|
||||
|
||||
__all__ = [
|
||||
'PythonDefinition',
|
||||
@@ -30,16 +31,16 @@ __all__ = [
|
||||
]
|
||||
|
||||
|
||||
def _python_docstring(doc: Union[str, None]) -> Union[PythonDocstring, None]:
|
||||
def _python_docstring(doc: str | None) -> PythonDocstring | None:
|
||||
"""
|
||||
Returns the PythonDocstring object if the docstring is a string and
|
||||
not ``None``.
|
||||
|
||||
:param doc: The docstring.
|
||||
:type doc: Union[str, None]
|
||||
:type doc: str | None
|
||||
|
||||
:return: The PythonDocstring object or ``None``.
|
||||
:rtype: Union[PythonDocstring, None]
|
||||
:rtype: PythonDocstring | None
|
||||
"""
|
||||
|
||||
return PythonDocstring(doc) if doc is not None else None
|
||||
@@ -53,7 +54,7 @@ class PythonDefinition:
|
||||
:param name: The name of the definition.
|
||||
:type name: str
|
||||
:param doc: The docstring.
|
||||
:type doc: Union[PythonDocstring, None]
|
||||
:type doc: PythonDocstring | None
|
||||
:param decorators: The definition decorators.
|
||||
:type decorators: list[str]
|
||||
|
||||
@@ -64,7 +65,7 @@ class PythonDefinition:
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
doc: Union[PythonDocstring, None],
|
||||
doc: PythonDocstring | None,
|
||||
decorators: list[str],
|
||||
) -> None:
|
||||
if keyword.iskeyword(name) or not name.isidentifier() or not name:
|
||||
@@ -120,9 +121,9 @@ class PythonFunctionDefinition(PythonDefinition):
|
||||
:param args: The arguments.
|
||||
:type args: list[PythonFunctionArgument]
|
||||
:param returns: The return type of the function or class.
|
||||
:type returns: Union[str, None]
|
||||
:type returns: str | None
|
||||
:param doc: The docstring.
|
||||
:type doc: Union[PythonDocstring, None]
|
||||
:type doc: PythonDocstring | None
|
||||
:param decorators: The definition decorators.
|
||||
:type decorators: list[str]
|
||||
|
||||
@@ -134,8 +135,8 @@ class PythonFunctionDefinition(PythonDefinition):
|
||||
self,
|
||||
name: str,
|
||||
args: list[PythonFunctionArgument],
|
||||
returns: Union[str, None],
|
||||
doc: Union[PythonDocstring, None],
|
||||
returns: str | None,
|
||||
doc: PythonDocstring | None,
|
||||
decorators: list[str],
|
||||
) -> None:
|
||||
super().__init__(name, doc, decorators)
|
||||
@@ -179,9 +180,9 @@ class PythonAsyncFunctionDefinition(PythonFunctionDefinition):
|
||||
:param args: The arguments.
|
||||
:type args: list[PythonFunctionArgument]
|
||||
:param returns: The return type of the function or class.
|
||||
:type returns: Union[str, None]
|
||||
:type returns: str | None
|
||||
:param doc: The docstring.
|
||||
:type doc: Union[PythonDocstring, None]
|
||||
:type doc: PythonDocstring | None
|
||||
:param decorators: The definition decorators.
|
||||
:type decorators: list[str]
|
||||
|
||||
@@ -199,7 +200,7 @@ class PythonClassDefinition(PythonDefinition):
|
||||
:param bases: The base classes.
|
||||
:type bases: list[str]
|
||||
:param doc: The docstring.
|
||||
:type doc: Union[PythonDocstring, None]
|
||||
:type doc: PythonDocstring | None
|
||||
:param decorators: The definition decorators.
|
||||
:type decorators: list[str]
|
||||
:param body:
|
||||
@@ -213,7 +214,7 @@ class PythonClassDefinition(PythonDefinition):
|
||||
self,
|
||||
name: str,
|
||||
bases: list[str],
|
||||
doc: Union[PythonDocstring, None],
|
||||
doc: PythonDocstring | None,
|
||||
decorators: list[str],
|
||||
body: list[PythonDefinition],
|
||||
) -> None:
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from enum import Enum
|
||||
import docstring_parser
|
||||
|
||||
__all__ = ['PythonDocstring']
|
||||
|
||||
@@ -13,13 +13,15 @@
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TypeAlias, Union
|
||||
|
||||
from ...exceptions import (
|
||||
InvalidNamespaceError,
|
||||
NamespaceNotFoundError,
|
||||
NamespaceExistsError,
|
||||
NamespaceNotFoundError,
|
||||
)
|
||||
from ...utils import assert_that_is_instance
|
||||
from typing import Union, TypeAlias, Dict, List
|
||||
|
||||
__all__ = [
|
||||
'PythonNamespace',
|
||||
@@ -51,7 +53,7 @@ class PythonNamespace:
|
||||
return f'{type(self).__name__}({self.name!r})'
|
||||
|
||||
|
||||
PythonPackageNamespaceDictType: TypeAlias = Dict[
|
||||
PythonPackageNamespaceDictType: TypeAlias = dict[
|
||||
str,
|
||||
Union[
|
||||
str,
|
||||
@@ -73,7 +75,7 @@ class PythonPackageNamespace(PythonNamespace):
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
sub_namespaces: List[PythonNamespace],
|
||||
sub_namespaces: list[PythonNamespace],
|
||||
) -> None:
|
||||
assert_that_is_instance(sub_namespaces, list)
|
||||
|
||||
@@ -81,7 +83,7 @@ class PythonPackageNamespace(PythonNamespace):
|
||||
|
||||
self._sub_namespaces = sub_namespaces
|
||||
|
||||
def namespace(self, sub_namespaces: List[str]) -> PythonNamespace:
|
||||
def namespace(self, sub_namespaces: list[str]) -> PythonNamespace:
|
||||
"""
|
||||
Returns the namespace object with a specific identifier, such as
|
||||
``['package', 'subpackage', 'module']``.
|
||||
@@ -205,7 +207,7 @@ class PythonPackageNamespace(PythonNamespace):
|
||||
self._sub_namespaces.append(namespace)
|
||||
|
||||
@property
|
||||
def sub_namespaces(self) -> List[PythonNamespace]:
|
||||
def sub_namespaces(self) -> list[PythonNamespace]:
|
||||
return self._sub_namespaces
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user