Skip to content

Commit

Permalink
Clean: normalize docstring format to google python style
Browse files Browse the repository at this point in the history
  • Loading branch information
allison-casey committed Jul 22, 2021
1 parent 8705450 commit 8343d65
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 86 deletions.
89 changes: 38 additions & 51 deletions hy/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down Expand 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
Expand Down Expand Up @@ -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 "<string>". 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 "<string>". 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)

Expand Down
23 changes: 11 additions & 12 deletions hy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 19 additions & 23 deletions hy/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8343d65

Please sign in to comment.