File size: 1,493 Bytes
6a86ad5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""Mixin classes for sharing functionality between unrelated classes.

This module is named with a leading underscore to signify to users that it's
"private" and only intended for internal use by the biomechanics module.

"""


__all__ = ['_NamedMixin']


class _NamedMixin:
    """Mixin class for adding `name` properties.

    Valid names, as will typically be used by subclasses as a suffix when
    naming automatically-instantiated symbol attributes, must be nonzero length
    strings.

    Attributes
    ==========

    name : str
        The name identifier associated with the instance. Must be a string of
        length at least 1.

    """

    @property
    def name(self) -> str:
        """The name associated with the class instance."""
        return self._name

    @name.setter
    def name(self, name: str) -> None:
        if hasattr(self, '_name'):
            msg = (
                f'Can\'t set attribute `name` to {repr(name)} as it is '
                f'immutable.'
            )
            raise AttributeError(msg)
        if not isinstance(name, str):
            msg = (
                f'Name {repr(name)} passed to `name` was of type '
                f'{type(name)}, must be {str}.'
            )
            raise TypeError(msg)
        if name in {''}:
            msg = (
                f'Name {repr(name)} is invalid, must be a nonzero length '
                f'{type(str)}.'
            )
            raise ValueError(msg)
        self._name = name