Name

Inheritance diagram of naming.Name

class naming.Name(name='', sep=' ')[source]

Base class for name objects.

Each subclass may have its own config attribute that should be a dictionary in the form of {field: pattern} where pattern is a valid regular expression.

Classes may as well have a drop iterable attribute representing the fileds they want to ignore from their bases and a join dictionary attribute for nesting existing fields into new ones (or to override other fields).

All field names should be unique. No duplicates are allowed.

Example:
>>> from naming import Name
>>> class MyName(Name):
...     config = dict(base=r'\w+')
...
>>> n = MyName()
>>> n.get()  # no name has been set on the object, convention is solved with {missing} fields
'{base}'
>>> n.values
{}
>>> n.name = 'hello_world'
>>> n
Name("hello_world")
>>> str(n)  # cast to string
'hello_world'
>>> n.values
{'base': 'hello_world'}
>>> # modify name and get values from field names
>>> n.base = 'through_field_name'
>>> n.values
{'base': 'through_field_name'}
>>> n.base
'through_field_name'
Parameters:
  • name (str) –

  • sep (str) –

static cast(value, name='')

Cast value to a grouped regular expression when name is provided.

Parameters:
  • value (str) –

  • name (str) –

Return type:

str

classmethod cast_config(config)

Cast config to grouped regular expressions.

Parameters:

config (Mapping[str, str]) –

Return type:

Dict[str, str]

get(**values)

Get a new name string from this object’s name values.

Parameters:

values – Variable keyword arguments where the key should refer to a field on this object that will use the provided value to build the new name.

Return type:

str

get_pattern_list()

Fields / properties names (sorted) to be used when building names. Defaults to the keys of self.config

Return type:

List[str]

config = mappingproxy({})
join = mappingproxy({})
property name: str

This object’s solved name.

Raises:

ValueError – If an invalid string is provided when setting the attribute.

property nice_name: str

This object’s pure name without fields not present in self.config.

property sep: str

The string that acts as a separator of all the fields in the name.

property values: Dict[str, str]

The field values of this object’s name as a dictionary in the form of {field: value}.