arelle.PythonUtil

See COPYRIGHT.md for copyright information. Python version specific utilities

do not convert 3 to 2

Module Contents

Classes

attrdict

utility to simulate an object with named fields from a dict

OrderedDefaultDict

call with default factory and optional sorted initial entries e.g., OrderedDefaultDict(list, ((1,11),(2,22),…))

OrderedSet

OrderedSet implementation copied from Python recipe: https://code.activestate.com/recipes/576694/

FrozenOrderedSet

Like frozenset vs set, this is the immutable counterpart to OrderedSet. Maintains insertion order and provides set-like operations without mutation.

FrozenDict

Functions

pyTypeName

pyNamedObject

lcStr

strTruncate

normalizeSpace

flattenSequence

flattenToSet

pyObjectSize

Recursively finds size of objects

tryRunCommand

Tries to return the results of the provided command. Returns stdout or None if the command exits with a non-zero code.

isLegacyAbs

Implements legacy behavior of os.path.isabs() prior to Python 3.13 where True was returned for paths beginning with single slashes on Windows.

Data

API

arelle.PythonUtil.STR_NUM_TYPES

()

arelle.PythonUtil.pyTypeName(object: Any) str
arelle.PythonUtil.pyNamedObject(name: str, *args: Any, **kwargs: Any) Any
arelle.PythonUtil.lcStr(value: str) str | type[str]
arelle.PythonUtil.strTruncate(value: str, length: int) str
arelle.PythonUtil.normalizeSpace(s: arelle.typing.OptionalString) arelle.typing.OptionalString
arelle.PythonUtil.SEQUENCE_TYPES

()

arelle.PythonUtil.flattenSequence(x: Any, sequence: list[Any] | None = None) list[Any]
arelle.PythonUtil.flattenToSet(x: Any, _set: set[Any] | None = None) set[Any]
class arelle.PythonUtil.attrdict(*args: Any, **kwargs: Any)

Bases: dict

utility to simulate an object with named fields from a dict

Initialization

Initialize self. See help(type(self)) for accurate signature.

clear()
copy()
get()
items()
keys()
pop()
popitem()
setdefault()
update()
values()
class arelle.PythonUtil.OrderedDefaultDict(*args: Any)

Bases: collections.OrderedDict

call with default factory and optional sorted initial entries e.g., OrderedDefaultDict(list, ((1,11),(2,22),…))

Initialization

Initialize self. See help(type(self)) for accurate signature.

move_to_end(key, last=False)
clear()
copy()
get()
items()
keys()
pop()
popitem()
setdefault()
update()
values()
arelle.PythonUtil.T

‘TypeVar(…)’

class arelle.PythonUtil.OrderedSet(iterable: collections.abc.Iterable[arelle.PythonUtil.T] | None = None)

Bases: collections.abc.MutableSet[arelle.PythonUtil.T]

OrderedSet implementation copied from Python recipe: https://code.activestate.com/recipes/576694/

Initialization

add(key: arelle.PythonUtil.T) None
update(other: collections.abc.Iterable[arelle.PythonUtil.T]) None
discard(key: arelle.PythonUtil.T) None
pop(last: bool = True) arelle.PythonUtil.T
remove(value)
clear()
isdisjoint(other)
class arelle.PythonUtil.FrozenOrderedSet(iterable: collections.abc.Iterable[arelle.PythonUtil.T] | None = None)

Bases: collections.abc.Set[arelle.PythonUtil.T]

Like frozenset vs set, this is the immutable counterpart to OrderedSet. Maintains insertion order and provides set-like operations without mutation.

Initialization

isdisjoint(other)
arelle.PythonUtil.KT

‘TypeVar(…)’

arelle.PythonUtil.VT

‘TypeVar(…)’

class arelle.PythonUtil.FrozenDict(data: collections.abc.Mapping[arelle.PythonUtil.KT, arelle.PythonUtil.VT] | None = None)

Bases: typing.Generic[arelle.PythonUtil.KT, arelle.PythonUtil.VT], collections.abc.Mapping[arelle.PythonUtil.KT, arelle.PythonUtil.VT]

get(key, default=None)
keys()
items()
values()
arelle.PythonUtil.pyObjectSize(obj: Any, seen: set[int] | None = None) int

Recursively finds size of objects

arelle.PythonUtil.tryRunCommand(*args: str) str | None

Tries to return the results of the provided command. Returns stdout or None if the command exits with a non-zero code.

arelle.PythonUtil.isLegacyAbs(path: str) bool

Implements legacy behavior of os.path.isabs() prior to Python 3.13 where True was returned for paths beginning with single slashes on Windows.