module testing.verify_code#

Inheritance diagram of mlprodict.testing.verify_code

Short summary#

module mlprodict.testing.verify_code

Looks into the code and detects error before finalizing the benchmark.

source on GitHub

Classes#

class

truncated documentation

CodeNodeVisitor

Visits the code, implements verification rules.

ImperfectPythonCode

Raised if the code shows errors.

Functions#

function

truncated documentation

verify_code

Verifies python code.

Properties#

property

truncated documentation

Rows

returns a list of dictionaries with all the elements of the code

Static Methods#

staticmethod

truncated documentation

print_node

Debugging purpose.

Methods#

method

truncated documentation

__init__

generic_visit

Overrides generic_visit to check it is not used.

generic_visit_args

Overrides generic_visit to keep track of the indentation and the node parent. The function will add field …

print_tree

Displays the tree of instructions.

push

Pushes an element into a list.

visit

Visits a node, a method must exist for every object class.

visit_

visit_Add

visit_alias

visit_And

visit_arg

visit_arguments

visit_Assign

visit_Attribute

visit_AugAssign

visit_BinOp

visit_BitAnd

visit_BoolOp

visit_Call

visit_ClassDef

visit_Compare

visit_comprehension

visit_Constant

visit_Dict

visit_Div

visit_Eq

visit_Expr

visit_ExtSlice

visit_FloorDiv

visit_FunctionDef

visit_GeneratorExp

visit_Gt

visit_GtE

visit_If

visit_IfExp

visit_Import

visit_ImportFrom

visit_In

visit_Index

visit_Invert

visit_Is

visit_IsNot

visit_keyword

visit_Lambda

visit_List

visit_ListComp

visit_Load

visit_Lt

visit_Mod

visit_Module

visit_Mult

visit_Name

visit_NameConstant

visit_Not

visit_NotEq

visit_Num

visit_Or

visit_Pow

visit_Return

visit_Slice

visit_Store

visit_Str

visit_Sub

visit_Subscript

visit_Tuple

visit_UnaryOp

visit_USub

Documentation#

Looks into the code and detects error before finalizing the benchmark.

source on GitHub

class mlprodict.testing.verify_code.CodeNodeVisitor#

Bases: NodeVisitor

Visits the code, implements verification rules.

source on GitHub

property Rows#

returns a list of dictionaries with all the elements of the code

source on GitHub

__init__()#
generic_visit(node)#

Overrides generic_visit to check it is not used.

source on GitHub

generic_visit_args(node, row)#

Overrides generic_visit to keep track of the indentation and the node parent. The function will add field row["children"] = visited nodes from here.

Parameters:
  • node – node which needs to be visited

  • row – row (a dictionary)

Returns:

See ast.NodeVisitor.generic_visit

source on GitHub

static print_node(node)#

Debugging purpose.

source on GitHub

print_tree()#

Displays the tree of instructions.

Returns:

string

source on GitHub

push(row)#

Pushes an element into a list.

source on GitHub

visit(node)#

Visits a node, a method must exist for every object class.

source on GitHub

exception mlprodict.testing.verify_code.ImperfectPythonCode#

Bases: RuntimeError

Raised if the code shows errors.

source on GitHub

mlprodict.testing.verify_code.verify_code(source, exc=True)#

Verifies python code.

Parameters:
  • source – source to look into

  • exc – raise an exception or return the list of missing identifiers

Returns:

tuple(missing identifiers, CodeNodeVisitor)

source on GitHub