QualName
Dotted-name algebra for command qualnames: QualName and PythonName.
duho.qualname
Dotted-name algebra for command qualnames.
A :class:QualName base defines the parts/parent/join/split algebra, a
:class:DotQualNamed mixes it into str with . as the separator, and
:class:PythonName, whose :meth:PythonName.new runs parts through
:func:duho.text.pysafe.
__all__ = ['QualName', 'DotQualNamed', 'PythonName']
module-attribute
DotQualNamed
Bases: QualName, str
A :class:QualName that is also a str, split on :attr:SEPARATOR.
SEPARATOR = '.'
class-attribute
instance-attribute
parts
cached
property
PythonName
Bases: DotQualNamed
A dotted name whose parts are Python-safe (via :func:duho.text.pysafe).
new(*parts, sanitize=True)
classmethod
Build a new instance by joining parts.
Each dotted part is coerced through :func:duho.text.pysafe unless
sanitize=False. Returns cls(name) (not hard-coded to
PythonName), so a subclass calling .new() keeps its own type.
Source code in src/duho/qualname.py
155 156 157 158 159 160 161 162 163 164 165 166 167 | |
QualName
Abstract dotted-name algebra: parts, parent, join/split, path mapping.
name
cached
property
The last part (e.g. "c" for "a.b.c").
parent
cached
property
The name with its last part dropped (e.g. "a.b" for "a.b.c").
parts
property
The name's parts, most-significant first (e.g. ("a", "b", "c")).
__truediv__(key)
self / key -- alias for self.qualjoin(self, key).
Source code in src/duho/qualname.py
75 76 77 | |
as_path(root='/')
This qualname's parts joined onto root (a :class:~pathlib.PurePath).
Source code in src/duho/qualname.py
123 124 125 126 127 128 | |
camelcase(start=0, end=None, *, separators=None)
CamelCase over parts[start:end], then re-split on separators.
An empty part (e.g. from a name with a leading, trailing or doubled
separator) is skipped rather than indexed into -- matching
:func:duho.text.camelcase's own empty-part guard.
Source code in src/duho/qualname.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
qualjoin(*parts)
classmethod
Join parts (strings, iterables of strings, or other qualnames).
Source code in src/duho/qualname.py
51 52 53 54 | |
qualsplit(name)
classmethod
Split name into its parts (a qualname's .parts if it has one).
Source code in src/duho/qualname.py
56 57 58 59 60 61 | |
relative_to(name)
This qualname's parts with name's (a required prefix) stripped.
Raises :class:ValueError with a readable message if name is not a
prefix of this qualname's parts (including if it is longer).
Source code in src/duho/qualname.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
with_name(name)
This qualname's parent joined with a new last part, name.
Source code in src/duho/qualname.py
63 64 65 | |