4.2. The namedtupledefs API

The namedtupledefs API covers a variety of interfaces for the processing of resource path addresses, and the search of resources. The initial set of interfaces forcusses on filesystem resources in a basic distributed environment. This covers in particular a basic set of call parameters, which are common for a subset of the call interfaces.

4.2.1. Class Options by Interfaces

Basic Application API

The following table displays the parameters supported by the interfaces.

interface

collections.namedtuple

namedtupledefs.namedtuple

parameters

[namedutple-python3]

fieldnames

c

c

fielddefaults (1)

c

module (2)

c

c

rename

c

c

typename

c

c

verbose

c

c

c:

Parameter as call parameters. For example the parameters rename and fielddefaults are used by the factory namedtupledefs.namedtuple() for the creation of the extended tuple class template as well as for the creation of the class. E.g.:

namedtupledefs.abc.namedtupledefs(
   'MyClass',                              # processed by namedtuple
   ('a', 'b',),                            # processed by namedtuple
   rename=True,                            # processed by namedtuple
   fielddefaults=(11, 22)                  # processed by __new__ for class and instance creation
)
(1):

Depends on the actual tuplefactory.

(2):

Depends on the implementation, Python3.6+.

Parameters

4.2.1.1. fieldnames

Symbolic names of fields with identical semantics as the standard library collections.namedtuple. When used in combination with the parameter fielddefaults the semantics changes to the behaviour of function parameters with default values, see [PYFUNC].

fieldnames := '(' <field-name> [, <fieldnames>] ')'
field-name := <valid-character-one>[<field-name-tail>]
field-name-tail := <valid-character>[<field-name-tail>]
valid-character-one := [a-zA-Z]
valid-character := [a-zA-Z_0-9]

See also usage of parameters, and [namedtuple].

4.2.1.2. fielddefaults

Optional support for default values of fieldnames. A list of values. Same semantics as the function call interfaces [PYFUNC],

fielddefaults := '(' <item-default> [, <fielddefaults>] ')'
item-default := '(' <key>, <value> ')'
key := (<item-index> | <item-name>)
value := <default-value>

4.2.1.3. module

Sets ‘__module__’ of the created class definition. Available beginning with Python-3.6.

See also usage of parameters, and [namedtuple].

4.2.1.4. rename

If True replaces silently invalid field names by ‘_<item-index>’. Available beginning with Python-2.7, in Python3 beginning with Python-3.1 - so not in Python-3.0.

See also usage of parameters, and [namedtuple].

4.2.1.5. typename

Name of returned class of type namedtuple. The actual registered top-level base class is namedtupledefsABC - underneath object of course.

See also usage of parameters, and [namedtuple].

4.2.1.6. verbose

Prints created class definition.

See also usage of parameters, and [namedtuple].

The call interface provides for groups of functions and classes with a set of common parameters and additional context specific modifications.

The provided function sets comprise the categories:

  • Filesystem Positions and Navigation

  • Canonical Node Address

Various common options are supported, which may not be available for each interface.

4.2.2. Created Named Tuple Class

The created named tuple class is extended by the default values fielddefaults, which is coverd by the creation interface.

In addition the method “_merge” is added to the template, which supports the type-accurate merge of named tuples. The standard collections.tuple returns for the addition(merge) of named tuples the base class tuple, while the namedtupledef.namedtuple returns a new instance of merged classes as a named tuple including combined default values.

4.2.3. Resources

  • [namedtuple] namedtuple - The Python Standard Library - lib/collections

  • [PYFUNC] The Python Language Reference - Function definitions