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.
- 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. - 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.
- Ignore frames by a (non-decorated) function.
- 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
IgnoreElem
(
)
— An element of the ignore list</>IgnoreModule
— Ignore calls from a module or its submodules</>IgnoreFilename
— Ignore calls from a module by matching its filename</>IgnoreDirname
— Ignore calls from modules inside a directory</>IgnoreStdlib
— Ignore standard libraries in sysconfig.get_python_lib(standard_lib=True)</>IgnoreFunction
— Ignore a non-decorated function</>IgnoreDecorated
— Ignore a decorated function</>IgnoreModuleQualname
— Ignore calls by qualified name in the module</>IgnoreFilenameQualname
— Ignore calls with given qualname in the module with the filename</>IgnoreOnlyQualname
— Ignore calls that match the given qualname, across all frames.</>IgnoreList
— The ignore list to match the frames to see if they should be ignored</>
create_ignore_elem
(
ignore_elem
)
(IgnoreElem) — Create an ignore element according to the type</>
varname.ignore.
IgnoreElem
(
)
An element of the ignore list
varname.ignore.
IgnoreModule
(
*ign_args
)
Ignore calls from a module or its submodules
__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</>
varname.ignore.
IgnoreFilename
(
*ign_args
)
Ignore calls from a module by matching its filename
__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</>
varname.ignore.
IgnoreDirname
(
*ign_args
)
Ignore calls from modules inside a directory
Currently used internally to ignore calls from standard libraries.
__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</>
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/.
__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</>
varname.ignore.
IgnoreFunction
(
*ign_args
)
Ignore a non-decorated function
__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</>
varname.ignore.
IgnoreDecorated
(
*ign_args
)
Ignore a decorated function
__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</>
varname.ignore.
IgnoreModuleQualname
(
*ign_args
)
Ignore calls by qualified name in the module
__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</>
varname.ignore.
IgnoreFilenameQualname
(
*ign_args
)
Ignore calls with given qualname in the module with the filename
__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</>
varname.ignore.
IgnoreOnlyQualname
(
*ign_args
)
Ignore calls that match the given qualname, across all frames.
__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</>
varname.ignore.
create_ignore_elem
(
ignore_elem
)
→ IgnoreElem
Create an ignore element according to the type
varname.ignore.
IgnoreList
(
ignore_list
)
The ignore list to match the frames to see if they should be ignored
create
(
ignore
,ignore_lambda
,ignore_varname
)
(IgnoreList) — Create an IgnoreList object</>get_frame
(
frame_no
)
(frame) — Get the right frame by the frame number</>nextframe_to_check
(
frame_no
,frameinfos
)
(int) — Find the next frame to check</>
create
(
ignore=None
, ignore_lambda=True
, ignore_varname=True
)
Create an IgnoreList object
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 decoratorsignore_lambda
(bool, optional) — whether ignore lambda functionsignore_varname
(bool, optional) — whether the calls from this package
The IgnoreList object
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.
frame_no
(int) — The index of current frame to checkframeinfos
(List) — The frame info objects
A number for Next N
th frame to check. 0 if no frame matched.
get_frame
(
frame_no
)
Get the right frame by the frame number
frame_no
(int) — The index of the frame to get
The desired frame
VarnameRetrievingError
— if any exceptions raised during the process.