generated from jCloud/repository-template
style: format source code using Ruff
This commit is contained in:
41 files changed
+6061
-5670
No files matched your search
@@ -29,8 +29,9 @@ __all__ = [
|
||||
'PythonClassDefinition',
|
||||
]
|
||||
|
||||
|
||||
def _python_docstring(doc: Union[str, None]) -> Union[PythonDocstring, None]:
|
||||
'''
|
||||
"""
|
||||
Returns the PythonDocstring object if the docstring is a string and
|
||||
not ``None``.
|
||||
|
||||
@@ -39,12 +40,13 @@ def _python_docstring(doc: Union[str, None]) -> Union[PythonDocstring, None]:
|
||||
|
||||
:return: The PythonDocstring object or ``None``.
|
||||
:rtype: Union[PythonDocstring, None]
|
||||
'''
|
||||
"""
|
||||
|
||||
return PythonDocstring(doc) if doc is not None else None
|
||||
|
||||
|
||||
class PythonDefinition:
|
||||
'''
|
||||
"""
|
||||
A base class for Python definition (a class, function or asynchronous
|
||||
function definition) classes.
|
||||
|
||||
@@ -57,7 +59,7 @@ class PythonDefinition:
|
||||
|
||||
:raises InvalidPythonIdentifierError: If the name is not a valid
|
||||
Python identifier.
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -68,7 +70,7 @@ class PythonDefinition:
|
||||
if keyword.iskeyword(name) or not name.isidentifier() or not name:
|
||||
raise InvalidPythonIdentifierError(
|
||||
'invalid identifier',
|
||||
identifier = name,
|
||||
identifier=name,
|
||||
)
|
||||
|
||||
assert_that_is_instance(doc, (PythonDocstring, types.NoneType))
|
||||
@@ -89,12 +91,12 @@ class PythonDefinition:
|
||||
|
||||
@classmethod
|
||||
def from_node(cls, node: ast.stmt) -> PythonDefinition:
|
||||
'''
|
||||
"""
|
||||
From an AST node.
|
||||
|
||||
:param node: The AST node.
|
||||
:type node: ast.stmt
|
||||
'''
|
||||
"""
|
||||
|
||||
return cls(
|
||||
node.name,
|
||||
@@ -107,8 +109,9 @@ class PythonDefinition:
|
||||
return False
|
||||
return self._arg_list() == value._arg_list()
|
||||
|
||||
|
||||
class PythonFunctionDefinition(PythonDefinition):
|
||||
'''
|
||||
"""
|
||||
A PythonDefinition subclass representing a Python function
|
||||
definition.
|
||||
|
||||
@@ -125,7 +128,7 @@ class PythonFunctionDefinition(PythonDefinition):
|
||||
|
||||
:raises InvalidPythonIdentifierError: If the name is not a valid
|
||||
Python identifier.
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -150,12 +153,12 @@ class PythonFunctionDefinition(PythonDefinition):
|
||||
|
||||
@classmethod
|
||||
def from_node(cls, node: ast.stmt) -> PythonFunctionDefinition:
|
||||
'''
|
||||
"""
|
||||
From an AST node.
|
||||
|
||||
:param node: The AST node.
|
||||
:type node: ast.stmt
|
||||
'''
|
||||
"""
|
||||
|
||||
return cls(
|
||||
node.name,
|
||||
@@ -165,8 +168,9 @@ class PythonFunctionDefinition(PythonDefinition):
|
||||
[ast.unparse(d) for d in node.decorator_list],
|
||||
)
|
||||
|
||||
|
||||
class PythonAsyncFunctionDefinition(PythonFunctionDefinition):
|
||||
'''
|
||||
"""
|
||||
A PythonDefinition subclass representing an asynchronous Python function
|
||||
definition.
|
||||
|
||||
@@ -183,10 +187,11 @@ class PythonAsyncFunctionDefinition(PythonFunctionDefinition):
|
||||
|
||||
:raises InvalidPythonIdentifierError: If the name is not a valid
|
||||
Python identifier.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
class PythonClassDefinition(PythonDefinition):
|
||||
'''
|
||||
"""
|
||||
A PythonDefinition subclass representing a Python class definition.
|
||||
|
||||
:param name: The name of the definition.
|
||||
@@ -202,7 +207,7 @@ class PythonClassDefinition(PythonDefinition):
|
||||
|
||||
:raises InvalidPythonIdentifierError: If the name is not a valid
|
||||
Python identifier.
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -227,12 +232,12 @@ class PythonClassDefinition(PythonDefinition):
|
||||
|
||||
@classmethod
|
||||
def from_node(cls, node: ast.stmt) -> PythonClassDefinition:
|
||||
'''
|
||||
"""
|
||||
From an AST node.
|
||||
|
||||
:param node: The AST node.
|
||||
:type node: ast.stmt
|
||||
'''
|
||||
"""
|
||||
|
||||
return cls(
|
||||
node.name,
|
||||
@@ -242,16 +247,12 @@ class PythonClassDefinition(PythonDefinition):
|
||||
[
|
||||
PythonFunctionDefinition.from_node(expr)
|
||||
if isinstance(expr, ast.FunctionDef)
|
||||
|
||||
else PythonAsyncFunctionDefinition.from_node(expr)
|
||||
if isinstance(expr, ast.AsyncFunctionDef)
|
||||
|
||||
else PythonClassDefinition.from_node(expr)
|
||||
|
||||
for expr in node.body
|
||||
if isinstance(
|
||||
expr,
|
||||
(ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)
|
||||
expr, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)
|
||||
)
|
||||
],
|
||||
)
|
||||
Reference in new issue
Block a user