scenario.reflex module

Reflexive programmation tools and Python augmentations.

REFLEX_LOGGER

Logger instance for reflexive programming.

qualname(obj)

Returns the qualified name of an object.

Parameters:

obj – Object to retrieve the qualified name for.

Returns:

Qualified name.

Note

Accessing directly the __qualname__ attribute makes mypy generate errors like ‘”…” has no attribute “__qualname__”’.

isiterable(obj)

Tells whether an object is iterable or not.

Parameters:

obj – Object to check.

Returns:

True when the object is iterable, False otherwise.

Inspired from https://stackoverflow.com/questions/1952464/in-python-how-do-i-determine-if-an-object-is-iterable#1952481.

importmodulefrompath(script_path)

Imports a module from its Python script path.

Parameters:

script_path – Python script path.

Returns:

Module loaded.

getloadedmodulefrompath(script_path)

Retrieves a module already loaded corresponding to the given path.

Parameters:

script_path – Python script path.

Returns:

Corresponding module if already loaded.

checkfuncqualname(file, line, func_name)

Tries to retrieve the fully qualified name of a function or method.

Parameters:
  • file – Path of the file the function is defined int.

  • line – Line number inside the function.

  • func_name – Short name of the function.

Returns:

Fully qualified name of the function, or func_name as is by default.

codelinecount(code)

Retrieves the number of lines of the given code object.

Parameters:

code – Code object which lines to count.

Returns:

Number of lines.

Apparently, inspect does give the straight forward information.

The co_lnotab attribute, being an “encoded mapping of line numbers to bytecode indices”, is our best chance for the purpose.

The https://svn.python.org/projects/python/branches/pep-0384/Objects/lnotab_notes.txt resource gives complementary information on how to parse this co_lnotab attribute.

co_lnotab depreciation.

According to https://www.python.org/dev/peps/pep-0626/#backwards-compatibility: “The co_lnotab attribute will be deprecated in 3.10 and removed in 3.12.”