Skip to content

varname.ignore

module

varname.ignore

The frame ignoring system for varname

There 4 mechanisms to ignore intermediate frames to determine the desired one so that a variable name should be retrieved at that frame.

  1. Ignore frames by a given module. Any calls inside it and inside its submodules will be ignored. A filename (path) to a module is also acceptable and recommended when code is executed by exec without module available.
  2. Ignore frames by a given pair of module and a qualified name (qualname). See 1) for acceptable modules. The qualname should be unique in that module.
  3. Ignore frames by a (non-decorated) function.
  4. Ignore frames by a decorated function. In this case, you can specified a tuple with the function and the number of decorators of it. The decorators on the wrapper function inside the decorators should also be counted.

Any frames in varname, standard libraries, and frames of any expressions like are ignored by default.

Classes
Functions
abstract class

varname.ignore.IgnoreElem()

An element of the ignore list

Methods
  • __init_subclass__(attrs) Define different attributes for subclasses</>
  • __repr__() (str) Representation of the element</>
  • match(frame_no, frameinfos) (bool) Whether the frame matches the ignore element</>
classmethod

__init_subclass__(attrs)

Define different attributes for subclasses

abstract method

match(frame_no, frameinfos) → bool

Whether the frame matches the ignore element

method

__repr__() → str

Representation of the element

class

varname.ignore.IgnoreModule(*ign_args)

Ignore calls from a module or its submodules

Methods
  • __init_subclass__(attrs) Define different attributes for subclasses</>
  • __repr__() (str) Representation of the element</>
  • match(frame_no, frameinfos) (bool) Whether the frame matches the ignore element</>
  • subclass_init(*ign_args) init function for subclasses</>
classmethod

__init_subclass__(attrs)

Define different attributes for subclasses

method

subclass_init(*ign_args)

init function for subclasses

method

__repr__() → str

Representation of the element

method

match(frame_no, frameinfos) → bool

Whether the frame matches the ignore element

class

varname.ignore.IgnoreFilename(*ign_args)

Ignore calls from a module by matching its filename

Methods
  • __init_subclass__(attrs) Define different attributes for subclasses</>
  • __repr__() (str) Representation of the element</>
  • match(frame_no, frameinfos) (bool) Whether the frame matches the ignore element</>
  • subclass_init(*ign_args) init function for subclasses</>
classmethod

__init_subclass__(attrs)

Define different attributes for subclasses

method

subclass_init(*ign_args)

init function for subclasses

method

__repr__() → str

Representation of the element

method

match(frame_no, frameinfos) → bool

Whether the frame matches the ignore element

class

varname.ignore.IgnoreDirname(*ign_args)

Ignore calls from modules inside a directory

Currently used internally to ignore calls from standard libraries.

Methods
  • __init_subclass__(attrs) Define different attributes for subclasses</>
  • __repr__() (str) Representation of the element</>
  • match(frame_no, frameinfos) (bool) Whether the frame matches the ignore element</>
  • subclass_init(*ign_args) init function for subclasses</>
classmethod

__init_subclass__(attrs)

Define different attributes for subclasses

method

subclass_init(*ign_args)

init function for subclasses

method

__repr__() → str

Representation of the element

method

match(frame_no, frameinfos) → bool

Whether the frame matches the ignore element

class

varname.ignore.IgnoreStdlib(*ign_args)

Ignore standard libraries in sysconfig.get_python_lib(standard_lib=True)

But we need to ignore 3rd-party packages under site-packages/.

Methods
  • __init_subclass__(attrs) Define different attributes for subclasses</>
  • __repr__() (str) Representation of the element</>
  • match(frame_no, frameinfos) (bool) Whether the frame matches the ignore element</>
  • subclass_init(*ign_args) init function for subclasses</>
classmethod

__init_subclass__(attrs)

Define different attributes for subclasses

method

subclass_init(*ign_args)

init function for subclasses

method

__repr__() → str

Representation of the element

method

match(frame_no, frameinfos) → bool

Whether the frame matches the ignore element

class

varname.ignore.IgnoreFunction(*ign_args)

Ignore a non-decorated function

Methods
  • __init_subclass__(attrs) Define different attributes for subclasses</>
  • __repr__() (str) Representation of the element</>
  • match(frame_no, frameinfos) (bool) Whether the frame matches the ignore element</>
  • subclass_init(*ign_args) init function for subclasses</>
classmethod

__init_subclass__(attrs)

Define different attributes for subclasses

method

subclass_init(*ign_args)

init function for subclasses

method

__repr__() → str

Representation of the element

method

match(frame_no, frameinfos) → bool

Whether the frame matches the ignore element

class

varname.ignore.IgnoreDecorated(*ign_args)

Ignore a decorated function

Methods
  • __init_subclass__(attrs) Define different attributes for subclasses</>
  • __repr__() (str) Representation of the element</>
  • match(frame_no, frameinfos) (bool) Whether the frame matches the ignore element</>
  • subclass_init(*ign_args) init function for subclasses</>
classmethod

__init_subclass__(attrs)

Define different attributes for subclasses

method

subclass_init(*ign_args)

init function for subclasses

method

__repr__() → str

Representation of the element

method

match(frame_no, frameinfos) → bool

Whether the frame matches the ignore element

class

varname.ignore.IgnoreModuleQualname(*ign_args)

Ignore calls by qualified name in the module

Methods
  • __init_subclass__(attrs) Define different attributes for subclasses</>
  • __repr__() (str) Representation of the element</>
  • match(frame_no, frameinfos) (bool) Whether the frame matches the ignore element</>
  • subclass_init(*ign_args) init function for subclasses</>
classmethod

__init_subclass__(attrs)

Define different attributes for subclasses

method

subclass_init(*ign_args)

init function for subclasses

method

__repr__() → str

Representation of the element

method

match(frame_no, frameinfos) → bool

Whether the frame matches the ignore element

class

varname.ignore.IgnoreFilenameQualname(*ign_args)

Ignore calls with given qualname in the module with the filename

Methods
  • __init_subclass__(attrs) Define different attributes for subclasses</>
  • __repr__() (str) Representation of the element</>
  • match(frame_no, frameinfos) (bool) Whether the frame matches the ignore element</>
  • subclass_init(*ign_args) init function for subclasses</>
classmethod

__init_subclass__(attrs)

Define different attributes for subclasses

method

subclass_init(*ign_args)

init function for subclasses

method

__repr__() → str

Representation of the element

method

match(frame_no, frameinfos) → bool

Whether the frame matches the ignore element

class

varname.ignore.IgnoreOnlyQualname(*ign_args)

Ignore calls that match the given qualname, across all frames.

Methods
  • __init_subclass__(attrs) Define different attributes for subclasses</>
  • __repr__() (str) Representation of the element</>
  • match(frame_no, frameinfos) (bool) Whether the frame matches the ignore element</>
  • subclass_init(*ign_args) init function for subclasses</>
classmethod

__init_subclass__(attrs)

Define different attributes for subclasses

method

subclass_init(*ign_args)

init function for subclasses

method

__repr__() → str

Representation of the element

method

match(frame_no, frameinfos) → bool

Whether the frame matches the ignore element

function

varname.ignore.create_ignore_elem(ignore_elem)IgnoreElem

Create an ignore element according to the type

class

varname.ignore.IgnoreList(ignore_list)

The ignore list to match the frames to see if they should be ignored

Methods
classmethod

create(ignore=None, ignore_lambda=True, ignore_varname=True)

Create an IgnoreList object

Parameters
  • ignore (Union, optional) An element of the ignore list, eitherA module (or filename of a module) A tuple of module (or filename) and qualified name A function A tuple of function and number of decorators
  • ignore_lambda (bool, optional) whether ignore lambda functions
  • ignore_varname (bool, optional) whether the calls from this package
Returns (IgnoreList)

The IgnoreList object

method

nextframe_to_check(frame_no, frameinfos)

Find the next frame to check

In modst cases, the next frame to check is the next adjacent frame. But for IgnoreDecorated, the next frame to check should be the next ignore[1]th frame.

Parameters
  • frame_no (int) The index of current frame to check
  • frameinfos (List) The frame info objects
Returns (int)

A number for Next Nth frame to check. 0 if no frame matched.

method

get_frame(frame_no)

Get the right frame by the frame number

Parameters
  • frame_no (int) The index of the frame to get
Returns (frame)

The desired frame

Raises
  • VarnameRetrievingError if any exceptions raised during the process.