anyconfig.utils
¶
Internal utility functions for anyconfig modules.
Changed in version 0.14.0:
Add ‘is_primitive_type’ to test if given object is primiitive type.
Changed in version 0.10.2:
Split and re-organize the module and export only some functions.
Added in version 0.9.5:
Add to abstract processors such like Parsers (loaders and dumpers).
- anyconfig.utils.is_primitive_type(obj)¶
Test if given object is a primitive type.
- Return type:
TypeGuard
[Union
[bool
,int
,float
,str
,bytes
]]
- anyconfig.utils.is_iterable(obj)¶
Test if given object is an iterable object.
- Return type:
TypeGuard
[Iterable
]
- anyconfig.utils.is_dict_like(obj)¶
Test if given object
obj
is an dict.- Return type:
TypeGuard
[dict
]
- anyconfig.utils.is_list_like(obj)¶
Test if given object
obj
is a list or -like one.- Return type:
TypeGuard
[Iterable
]
- anyconfig.utils.get_path_from_stream(strm, *, safe=False)¶
Try to get file path from given file or file-like object ‘strm’.
- Parameters:
strm (
IO
) – A file or file-like object might have its file path info- Return type:
str
- Returns:
file path or None
- Raises:
ValueError
- anyconfig.utils.groupby(itr, key_fn=None)¶
Provide an wrapper function of itertools.groupby to sort each results.
- Parameters:
itr (
Iterable
[Any
]) – Iterable object, a list/tuple/genrator, etc.key_fn (
Optional
[Callable
[...
,Any
]]) – Key function to sort ‘itr’.
- Return type:
Iterable
[tuple
[Any
,Iterable
[Any
]]]
- anyconfig.utils.concat(xss)¶
Concatenates a list of lists.
- Return type:
list
[Any
]
- anyconfig.utils.filter_options(keys, options)¶
Filter ‘options’ with given ‘keys’.
- Parameters:
keys (
Iterable
[str
]) – key names of optional keyword argumentsoptions (
Mapping
[str
,Any
]) – optional keyword arguments to filter with ‘keys’
>>> filter_options(("aaa", ), {"aaa": 1, "bbb": 2}) :rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`dict\`\\ \\\[\:py\:class\:\`str\`\, \:py\:data\:\`\~typing.Any\`\]` {'aaa': 1} >>> filter_options(("aaa", ), {"bbb": 2}) {}
- anyconfig.utils.noop(val, *_args, **_kwargs)¶
Do nothing.
- Return type:
Any
>>> noop(1) 1