From 8343d6597acc50a2890069b27efd670be130fb94 Mon Sep 17 00:00:00 2001 From: Allison Casey Date: Wed, 21 Jul 2021 20:05:55 -0400 Subject: [PATCH] Clean: normalize docstring format to google python style --- hy/compiler.py | 89 +++++++++++++++++++++----------------------------- hy/errors.py | 23 +++++++------ hy/macros.py | 42 +++++++++++------------- 3 files changed, 68 insertions(+), 86 deletions(-) diff --git a/hy/compiler.py b/hy/compiler.py index a42c3a7d5..d2f2ec1e8 100755 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -19,15 +19,13 @@ def ast_compile(a: ast.AST, filename: str, mode: str) -> types.CodeType: """Compile AST. - Parameters - ---------- - a: instance of `ast.AST` - filename: Filename used for run-time error messages - mode: `compile` mode parameter - - Returns - ------- - out : instance of `types.CodeType` + Args: + a: instance of `ast.AST` + filename: Filename used for run-time error messages + mode: `compile` mode parameter + + Returns: + out : instance of `types.CodeType` """ return compile(a, filename, mode, hy_ast_compile_flags) @@ -38,14 +36,12 @@ def calling_module(n: int=1) -> types.ModuleType: As a fallback, this will import a module using the calling frame's globals value of `__name__`. - Parameters - ---------- - n: The number of levels up the stack from this function call. - The default is one level up. + Args: + n: The number of levels up the stack from this function call. + The default is one level up. - Returns - ------- - out: The module at stack level `n + 1` or `None`. + Returns: + out: The module at stack level `n + 1` or `None`. """ frame_up = inspect.stack(0)[n + 1][0] module = inspect.getmodule(frame_up) @@ -284,14 +280,13 @@ def __init__( source: Optional[str] = None, ): """ - Parameters - ---------- - module: Module name or object in which the Hy tree is evaluated. - filename: The name of the file for the source to be compiled. - This is optional information for informative error messages and - debugging. - source: The source for the file, if any, being compiled. This is optional - information for informative error messages and debugging. + Args: + module: Module name or object in which the Hy tree is evaluated. + filename: The name of the file for the source to be compiled. + This is optional information for informative error messages and + debugging. + source: The source for the file, if any, being compiled. This is optional + information for informative error messages and debugging. """ self.anon_var_count = 0 self.temp_if = None @@ -749,34 +744,26 @@ def hy_compile( ) -> ast.AST: """Compile a hy.models.Object tree into a Python AST Module. - Parameters - ---------- - tree: The Hy AST object to compile. - - module: Module, or name of the module, in which the Hy tree is evaluated. - The module associated with `compiler` takes priority over this value. - - root: Root object for the Python AST tree. - - get_expr: If true, return a tuple with `(root_obj, last_expression)`. - - compiler: An existing Hy compiler to use for compilation. Also serves as - the `module` value when given. - - filename: The filename corresponding to the source for `tree`. This will be - overridden by the `filename` field of `tree`, if any; otherwise, it - defaults to "". When `compiler` is given, its `filename` field - value is always used. - - source: A string containing the source code for `tree`. This will be - overridden by the `source` field of `tree`, if any; otherwise, - if `None`, an attempt will be made to obtain it from the module given by - `module`. When `compiler` is given, its `source` field value is always - used. + Args: + tree: The Hy AST object to compile. + module: Module, or name of the module, in which the Hy tree is evaluated. + The module associated with `compiler` takes priority over this value. + root: Root object for the Python AST tree. + get_expr: If true, return a tuple with `(root_obj, last_expression)`. + compiler: An existing Hy compiler to use for compilation. Also serves as + the `module` value when given. + filename: The filename corresponding to the source for `tree`. This will be + overridden by the `filename` field of `tree`, if any; otherwise, it + defaults to "". When `compiler` is given, its `filename` field + value is always used. + source: A string containing the source code for `tree`. This will be + overridden by the `source` field of `tree`, if any; otherwise, + if `None`, an attempt will be made to obtain it from the module given by + `module`. When `compiler` is given, its `source` field value is always + used. - Returns - ------- - out : A Python AST tree + Returns: + A Python AST tree """ module = get_compiler_module(module, compiler, False) diff --git a/hy/errors.py b/hy/errors.py index c4946df94..5c0a1a09d 100644 --- a/hy/errors.py +++ b/hy/errors.py @@ -46,18 +46,17 @@ def __init__( colno: int = 1, ): """ - Parameters - ---------- - message: The message to display for this error. - expression: The Hy expression generating this error. - filename: The filename for the source code generating this error. - Expression-provided information will take precedence of this value. - source: The actual source code generating this error. Expression-provided - information will take precedence of this value. - lineno: The line number of the error. Expression-provided information will - take precedence of this value. - colno: The column number of the error. Expression-provided information - will take precedence of this value. + Args: + message: The message to display for this error. + expression: The Hy expression generating this error. + filename: The filename for the source code generating this error. + Expression-provided information will take precedence of this value. + source: The actual source code generating this error. Expression-provided + information will take precedence of this value. + lineno: The line number of the error. Expression-provided information will + take precedence of this value. + colno: The column number of the error. Expression-provided information + will take precedence of this value. """ self.msg = message self.compute_lineinfo(expression, filename, source, lineno, colno) diff --git a/hy/macros.py b/hy/macros.py index fa33d1ee7..d06d8f1c4 100644 --- a/hy/macros.py +++ b/hy/macros.py @@ -126,20 +126,18 @@ def require( This function is called from the macro also named `require`. - Parameters - ---------- - source_module: The module from which macros are to be imported. - target_module: The module into which the macros will be loaded. If `None`, then - the caller's namespace. - The latter is useful during evaluation of generated AST/bytecode. - assignments: The string "ALL" or a list of macro name and alias pairs. - prefix: If nonempty, its value is prepended to the name of each imported macro. - This allows one to emulate namespaced macros, like - "mymacromodule.mymacro", which looks like an attribute of a module. - - Returns - ------- - out: Whether or not macros were actually transferred. + Args: + source_module: The module from which macros are to be imported. + target_module: The module into which the macros will be loaded. If `None`, then + the caller's namespace. + The latter is useful during evaluation of generated AST/bytecode. + assignments: The string "ALL" or a list of macro name and alias pairs. + prefix: If nonempty, its value is prepended to the name of each imported macro. + This allows one to emulate namespaced macros, like + "mymacromodule.mymacro", which looks like an attribute of a module. + + Returns: + Whether or not macros were actually transferred. """ if target_module is None: parent_frame = inspect.stack()[1][0] @@ -296,16 +294,14 @@ def macroexpand( outer-most namespace--e.g. the one given by the `module` parameter--is used as a fallback. - Parameters - ---------- - tree: Hy AST tree. - module: Module used to determine the local namespace for macros. - compiler: The compiler object passed to expanded macros. - once: Only expand the first macro in `tree`. + Args: + tree: Hy AST tree. + module: Module used to determine the local namespace for macros. + compiler: The compiler object passed to expanded macros. + once: Only expand the first macro in `tree`. - Returns - ------ - out: Returns a mutated tree with macros expanded. + Returns: + a mutated tree with macros expanded. """ if not inspect.ismodule(module): module = importlib.import_module(module)