Test Failed
Push — master ( 4d7d02...6b0277 )
by Oliver
02:34
created

personroles.mop_role.MoP.__post_init__()   A

Complexity

Conditions 2

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nop 1
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
"""
4
A set of dataclasses concerning roles of persons and their particulars.
5
"""
6
import os
7
import sys
8
from dataclasses import dataclass, field
9
from typing import List, Set
10
11
PACKAGE_PARENT = ".."
12
SCRIPT_DIR = os.path.dirname(
13
    os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__)))
14
)  # isort:skip # noqa # pylint: disable=wrong-import-position
15
sys.path.append(
16
    os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT))
17
)  # isort: skip # noqa # pylint: disable=wrong-import-position
18
19
from personroles.politician_role import Politician  # type: ignore  # noqa
20
from personroles.resources.helpers import AttrDisplay  # type: ignore # noqa
21
from personroles.resources.helpers import NotInRange  # type: ignore # noqa
22
23
24
@dataclass
0 ignored issues
show
Coding Style Naming introduced by
Class name "_MoP_default" doesn't conform to PascalCase naming style ('[^\\W\\da-z][^\\W_]+$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
25
class _MoP_default:
26
    parl_pres: bool = field(default=False)
27
    parl_vicePres: bool = field(default=False)
0 ignored issues
show
Coding Style Naming introduced by
Attribute name "parl_vicePres" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
28
    parliament_entry: str = field(default="unknown")  # date string: "11.3.2015"  # noqa
29
    parliament_exit: str = field(default="unknown")  # dto.
30
    speeches: List[str] = field(
31
        default_factory=lambda: []
32
    )  # identifiers for speeches  # noqa
33
    reactions: List[str] = field(
34
        default_factory=lambda: []
35
    )  # identifiers for reactions
36
    membership: Set[str] = field(
37
        default_factory=lambda: set()
0 ignored issues
show
Unused Code introduced by
This lambda might be unnecessary.
Loading history...
38
    )  # years like ["2010", "2011", ...]
39
40
41
@dataclass
0 ignored issues
show
Coding Style Naming introduced by
Class name "_MoP_base" doesn't conform to PascalCase naming style ('[^\\W\\da-z][^\\W_]+$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
42
class _MoP_base:
43
    legislature: str
44
    state: str
45
46
47
@dataclass
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
best-practice introduced by
Too many ancestors (15/7)
Loading history...
48
class MoP(_MoP_default, Politician, _MoP_base, AttrDisplay):
49
    def __post_init__(self):
50
        if int(self.legislature) not in range(14, 18):
0 ignored issues
show
Unused Code introduced by
Unnecessary "else" after "raise"
Loading history...
51
            raise NotInRange("Number for legislature not in range")
52
        else:
53
            self.membership.add(self.legislature)
54
        Politician.__post_init__(self)
55
56
57
if __name__ == "__main__":
58
59
    mop = MoP(
60
        "14",
61
        "NRW",
62
        "SPD",  # type: ignore
63
        "Tom",  # type: ignore
64
        "Schwadronius",
65
        party_entry="1990",  # type: ignore
66
        peer_title="Junker von",
67
        date_of_birth="1950",
68
    )
69
    print(mop)
70
71
    mop.add_Party("Grüne", party_entry="30.11.1999")
72
    mop.change_ward("Düsseldorf II")
73
    print(mop)
74