Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jobs:
matrix:
python-version: [ 3.8 ]
os: [ ubuntu-latest ]
linter-env: ["linting", "type_check"]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -18,6 +19,6 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install tox
- name: Linting bo4e
- name: Run ${{ matrix.linter-env }}
run: |
tox -e linting
tox -e ${{ matrix.linter-env }}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ markers = ["datafiles: load datafiles"]
max-line-length = 120

[tool.isort]
line_length = 120
line_length = 120
8 changes: 5 additions & 3 deletions src/bo4e/bo/ansprechpartner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
"""
import attr
from marshmallow import fields
from marshmallow_enum import EnumField
from bo4e.com.rufnummer import Rufnummer, RufnummerSchema
from bo4e.com.adresse import Adresse, AdresseSchema
from marshmallow_enum import EnumField # type:ignore
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have to check the enum topic again. I think they are not well implemented.

Copy link
Copy Markdown
Contributor Author

@hf-kklein hf-kklein Oct 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this specific line the problem is the marshmallow_enum package itself.


from bo4e.bo.geschaeftsobjekt import Geschaeftsobjekt, GeschaeftsobjektSchema
from bo4e.bo.geschaeftspartner import Geschaeftspartner, GeschaeftspartnerSchema
from bo4e.com.adresse import Adresse, AdresseSchema
from bo4e.com.rufnummer import Rufnummer, RufnummerSchema
from bo4e.com.zustaendigkeit import Zustaendigkeit, ZustaendigkeitSchema
from bo4e.enum.anrede import Anrede
from bo4e.enum.botyp import BoTyp
from bo4e.enum.titel import Titel


# pylint: disable=too-many-instance-attributes, too-few-public-methods
@attr.s(auto_attribs=True, kw_only=True)
class Ansprechpartner(Geschaeftsobjekt):
Expand Down
18 changes: 14 additions & 4 deletions src/bo4e/bo/geschaeftsobjekt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@
and corresponding marshmallow schema for de-/serialization
"""
# pylint: disable=unused-argument, too-few-public-methods
from typing import List, Optional
from typing import List, Optional, Type

import attr
from marshmallow import fields, post_load
from marshmallow_enum import EnumField
from marshmallow_enum import EnumField # type:ignore

from bo4e.com.externereferenz import ExterneReferenz, ExterneReferenzSchema
from bo4e.enum.botyp import BoTyp
from bo4e.schemata.caseconverterschema import CaseConverterSchema


def _create_empty_referenzen_list() -> List[ExterneReferenz]:
"""
A method with a type hint to please mypy
https://stackoverflow.com/a/61281305/10009545
:return:
"""
return []
Comment on lines +17 to +23
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not get the connection between this function and the linked SO.
They are talking about Union issue. but here is no Union.
Maybe I am to tired to see it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the thing is that the empty list [] (of type List[Any]) does not have the type expected here. That's why I'm "hiding" the empty list returned in a function that has a type hint that matches mypys expectations. This idea is copied from the "Approach 2 - Use a type-hinted function for empty list assignment]" of the linked SO answer.



@attr.s(auto_attribs=True, kw_only=True)
class Geschaeftsobjekt:
"""
Expand All @@ -25,7 +35,7 @@ class Geschaeftsobjekt:

# optional attributes
externe_referenzen: Optional[List[ExterneReferenz]] = attr.ib(
default=[], validator=attr.validators.instance_of(List)
default=_create_empty_referenzen_list(), validator=attr.validators.instance_of(List) # type:ignore
)


Expand All @@ -36,7 +46,7 @@ class GeschaeftsobjektSchema(CaseConverterSchema):
"""

# class_name is needed to use the correct schema for deserialization.
class_name = Geschaeftsobjekt
class_name: Type[Geschaeftsobjekt] = Geschaeftsobjekt

# required attributes
versionstruktur = fields.String()
Expand Down
23 changes: 12 additions & 11 deletions src/bo4e/bo/geschaeftspartner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
and corresponding marshmallow schema for de-/serialization
"""
# pylint: disable=too-many-instance-attributes, too-few-public-methods
from typing import List
from typing import List, Optional, Type

import attr
from marshmallow import fields
from marshmallow_enum import EnumField
from marshmallow_enum import EnumField # type:ignore

from bo4e.bo.geschaeftsobjekt import Geschaeftsobjekt, GeschaeftsobjektSchema
from bo4e.com.adresse import Adresse, AdresseSchema
from bo4e.enum.anrede import Anrede
Expand All @@ -30,15 +31,15 @@ class Geschaeftspartner(Geschaeftsobjekt):

# optional attributes
anrede: Anrede = attr.ib(default=None)
name2: str = attr.ib(default=None)
name3: str = attr.ib(default=None)
hrnummer: str = attr.ib(default=None)
amtsgericht: str = attr.ib(default=None)
name2: Optional[str] = attr.ib(default=None)
name3: Optional[str] = attr.ib(default=None)
hrnummer: Optional[str] = attr.ib(default=None)
amtsgericht: Optional[str] = attr.ib(default=None)
kontaktweg: List[Kontaktart] = attr.ib(default=[])
umsatzsteuer_id: str = attr.ib(default=None)
glaeubiger_id: str = attr.ib(default=None)
e_mail_adresse: str = attr.ib(default=None)
website: str = attr.ib(default=None)
umsatzsteuer_id: Optional[str] = attr.ib(default=None)
glaeubiger_id: Optional[str] = attr.ib(default=None)
e_mail_adresse: Optional[str] = attr.ib(default=None)
website: Optional[str] = attr.ib(default=None)
partneradresse: Adresse = attr.ib(default=None)


Expand All @@ -49,7 +50,7 @@ class GeschaeftspartnerSchema(GeschaeftsobjektSchema):

# class_name is needed to use the correct schema for deserialisation.
# see function `deserialize` in geschaeftsobjekt.py
class_name = Geschaeftspartner
class_name: Type[Geschaeftspartner] = Geschaeftspartner

# required attributes
name1 = fields.Str()
Expand Down
4 changes: 2 additions & 2 deletions src/bo4e/bo/marktlokation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

import attr
from marshmallow import fields
from marshmallow_enum import EnumField
from marshmallow_enum import EnumField # type:ignore

from bo4e.bo.geschaeftsobjekt import Geschaeftsobjekt, GeschaeftsobjektSchema
from bo4e.bo.geschaeftspartner import Geschaeftspartner, GeschaeftspartnerSchema
from bo4e.com.adresse import Adresse, AdresseSchema
Expand All @@ -22,7 +23,6 @@
from bo4e.enum.sparte import Sparte
from bo4e.enum.verbrauchsart import Verbrauchsart


_malo_id_pattern = re.compile(r"^[1-9][\d]{10}$")


Expand Down
5 changes: 3 additions & 2 deletions src/bo4e/bo/marktteilnehmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
and corresponding marshmallow schema for de-/serialization
"""
import attr
from marshmallow import fields
from marshmallow_enum import EnumField
from attr.validators import matches_re
from marshmallow import fields
from marshmallow_enum import EnumField # type:ignore

from bo4e.bo.geschaeftspartner import Geschaeftspartner, GeschaeftspartnerSchema
from bo4e.enum.botyp import BoTyp
from bo4e.enum.marktrolle import Marktrolle
Expand Down
4 changes: 2 additions & 2 deletions src/bo4e/bo/messlokation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from typing import List, Optional

import attr
from iso3166 import countries
from iso3166 import countries # type:ignore
from marshmallow import fields
from marshmallow_enum import EnumField
from marshmallow_enum import EnumField # type:ignore

from bo4e.bo.geschaeftsobjekt import Geschaeftsobjekt, GeschaeftsobjektSchema
from bo4e.bo.zaehler import Zaehler, ZaehlerSchema
Expand Down
10 changes: 6 additions & 4 deletions src/bo4e/bo/vertrag.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
"""
from datetime import datetime
from typing import List, Optional

import attr
from marshmallow import fields
from marshmallow_enum import EnumField
from marshmallow_enum import EnumField # type:ignore

from bo4e.bo.geschaeftsobjekt import Geschaeftsobjekt, GeschaeftsobjektSchema
from bo4e.bo.geschaeftspartner import Geschaeftspartner, GeschaeftspartnerSchema
from bo4e.com.vertragsteil import Vertragsteil, VertragsteilSchema
from bo4e.com.vertragskonditionen import Vertragskonditionen, VertragskonditionenSchema
from bo4e.com.unterschrift import Unterschrift, UnterschriftSchema
from bo4e.com.vertragskonditionen import Vertragskonditionen, VertragskonditionenSchema
from bo4e.com.vertragsteil import Vertragsteil, VertragsteilSchema
from bo4e.enum.botyp import BoTyp
from bo4e.enum.sparte import Sparte
from bo4e.enum.vertragsart import Vertragsart
from bo4e.enum.vertragsstatus import Vertragsstatus
from bo4e.enum.sparte import Sparte


# pylint: disable=unused-argument
def at_least_one_vertragsteil(instance, attribute, value):
Expand Down
3 changes: 2 additions & 1 deletion src/bo4e/bo/zaehler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import attr
from marshmallow import fields
from marshmallow_enum import EnumField
from marshmallow_enum import EnumField # type:ignore

from bo4e.bo.geschaeftsobjekt import Geschaeftsobjekt, GeschaeftsobjektSchema
from bo4e.bo.geschaeftspartner import Geschaeftspartner, GeschaeftspartnerSchema
Expand All @@ -19,6 +19,7 @@
from bo4e.enum.zaehlerauspraegung import Zaehlerauspraegung
from bo4e.enum.zaehlertyp import Zaehlertyp


# pylint: disable=unused-argument
def at_least_one_zaehlwerk(instance, attribute, value):
"""
Expand Down
5 changes: 3 additions & 2 deletions src/bo4e/com/adresse.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

import attr
from marshmallow import fields, post_load
from marshmallow_enum import EnumField
from marshmallow_enum import EnumField # type:ignore

from bo4e.com.com import COM, COMSchema
from bo4e.enum.landescode import Landescode

Expand Down Expand Up @@ -42,7 +43,7 @@ class Adresse(COM):
postfach: str = attr.ib(default=None, validator=strasse_xor_postfach)
adresszusatz: str = attr.ib(default=None)
co_ergaenzung: str = attr.ib(default=None)
landescode: Landescode = attr.ib(default=Landescode.DE)
landescode: Landescode = attr.ib(default=Landescode.DE) # type:ignore


class AdresseSchema(COMSchema):
Expand Down
2 changes: 2 additions & 0 deletions src/bo4e/com/com.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
Contains base class for all components
"""
import attr

from bo4e.schemata.caseconverterschema import CaseConverterSchema


# pylint: disable=too-few-public-methods
@attr.s(auto_attribs=True, kw_only=True)
class COM:
Expand Down
4 changes: 3 additions & 1 deletion src/bo4e/com/dienstleistung.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

import attr
from marshmallow import fields, post_load
from marshmallow_enum import EnumField
from marshmallow_enum import EnumField # type:ignore

from bo4e.com.com import COM, COMSchema
from bo4e.enum.dienstleistungstyp import Dienstleistungstyp


# pylint: disable=too-few-public-methods
@attr.s(auto_attribs=True, kw_only=True)
class Dienstleistung(COM):
Expand Down
1 change: 1 addition & 0 deletions src/bo4e/com/externereferenz.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
import attr
from marshmallow import fields, post_load

from bo4e.com.com import COM, COMSchema


Expand Down
4 changes: 3 additions & 1 deletion src/bo4e/com/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

import attr
from marshmallow import fields, post_load
from marshmallow_enum import EnumField
from marshmallow_enum import EnumField # type:ignore

from bo4e.com.com import COM, COMSchema
from bo4e.enum.geraetetyp import Geraetetyp


# pylint: disable=too-few-public-methods
@attr.s(auto_attribs=True, kw_only=True)
class Hardware(COM):
Expand Down
1 change: 1 addition & 0 deletions src/bo4e/com/katasteradresse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
import attr
from marshmallow import fields, post_load

from bo4e.com.com import COM, COMSchema


Expand Down
3 changes: 2 additions & 1 deletion src/bo4e/com/menge.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

import attr
from marshmallow import fields, post_load
from marshmallow_enum import EnumField
from marshmallow_enum import EnumField # type:ignore

from bo4e.com.com import COM, COMSchema
from bo4e.enum.mengeneinheit import Mengeneinheit


# pylint: disable=too-few-public-methods
@attr.s(auto_attribs=True, kw_only=True)
class Menge(COM):
Expand Down
3 changes: 2 additions & 1 deletion src/bo4e/com/messlokationszuordnung.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

import attr
from marshmallow import fields, post_load
from marshmallow_enum import EnumField
from marshmallow_enum import EnumField # type:ignore

from bo4e.com.com import COM, COMSchema
from bo4e.enum.arithmetische_operation import ArithmetischeOperation

Expand Down
4 changes: 3 additions & 1 deletion src/bo4e/com/rufnummer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

import attr
from marshmallow import fields, post_load
from marshmallow_enum import EnumField
from marshmallow_enum import EnumField # type:ignore

from bo4e.com.com import COM, COMSchema
from bo4e.enum.rufnummernart import Rufnummernart


# pylint: disable=too-few-public-methods
@attr.s(auto_attribs=True, kw_only=True)
class Rufnummer(COM):
Expand Down
3 changes: 3 additions & 0 deletions src/bo4e/com/unterschrift.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
and corresponding marshmallow schema for de-/serialization
"""
from datetime import datetime

import attr
from marshmallow import fields, post_load

from bo4e.com.com import COM, COMSchema


# pylint: disable=too-few-public-methods
@attr.s(auto_attribs=True, kw_only=True)
class Unterschrift(COM):
Expand Down
3 changes: 3 additions & 0 deletions src/bo4e/com/vertragskonditionen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
and corresponding marshmallow schema for de-/serialization
"""
from decimal import Decimal

import attr
from marshmallow import fields, post_load

from bo4e.com.com import COM, COMSchema
from bo4e.com.zeitraum import Zeitraum, ZeitraumSchema


# pylint: disable=too-few-public-methods
@attr.s(auto_attribs=True, kw_only=True)
class Vertragskonditionen(COM):
Expand Down
5 changes: 4 additions & 1 deletion src/bo4e/com/vertragsteil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
Contains Vertragsteil class
and corresponding marshmallow schema for de-/serialization
"""
from typing import Optional
from datetime import datetime
from typing import Optional

import attr
from marshmallow import fields, post_load

from bo4e.com.com import COM, COMSchema
from bo4e.com.menge import Menge, MengeSchema


# pylint: disable=too-few-public-methods
@attr.s(auto_attribs=True, kw_only=True)
class Vertragsteil(COM):
Expand Down
2 changes: 1 addition & 1 deletion src/bo4e/com/zaehlwerk.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import attr
from attr.validators import matches_re
from marshmallow import fields, post_load
from marshmallow_enum import EnumField
from marshmallow_enum import EnumField # type:ignore

from bo4e.com.com import COM, COMSchema
from bo4e.enum.energierichtung import Energierichtung
Expand Down
Loading