Coverage for src/metador_core/util/__init__.py: 100%
13 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-02 09:33 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-02 09:33 +0000
1import re
2import sys
3from functools import lru_cache
4from typing import Iterable
6cache = lru_cache(maxsize=None) # for 3.8 compat
9def eprint(*args, **kwargs):
10 """Print to error stream."""
11 print(*args, file=sys.stderr, **kwargs)
14def drop(n: int, it: Iterable):
15 """Drop fixed number of elements from iterator."""
16 return (x for i, x in enumerate(it) if i >= n)
19def is_public_name(n: str):
20 """Return whether a name is public (does not start with _)."""
21 return n[0] != "_"
24def pythonize_name(name: str):
25 """Sanitize a string to be a valid Python variable name."""
26 return re.sub(r"\W|^(?=\d)", "_", " ".join(name.split()))