Skip to content

Commit

Permalink
Changed Code to be based on Item class and linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
javihern98 committed Apr 10, 2024
1 parent 75991b4 commit 54d4ef9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 25 deletions.
62 changes: 43 additions & 19 deletions src/pysdmx/model/__base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@

from msgspec import Struct

from pysdmx.model import Contact


class Annotation(Struct, frozen=True, omit_defaults=True):
"""
The Annotation is used
to convey extra information to describe any SDMX construct. This information may be in the
form of a URL reference and/or a multilingual text (represented by the association to
"""Annotation class.
It is used to convey extra information to describe any
SDMX construct.
This information may be in the form of a URL reference and/or
a multilingual text (represented by the association to
InternationalString).
Attributes:
Expand Down Expand Up @@ -38,8 +42,10 @@ def __str__(self) -> str:


class AnnotableArtefact(Struct, frozen=True, omit_defaults=True):
"""
Superclass of all SDMX artefacts. Contains the list of annotations.
"""Annotable Artefact class.
Superclass of all SDMX artefacts.
Contains the list of annotations.
Attributes:
annotations: The list of annotations attached to the artefact.
Expand All @@ -53,13 +59,17 @@ def __iter__(self) -> Iterator[Annotation]:

def __str__(self) -> str:
"""Returns a human-friendly description."""
return f"{self.__class__.__name__}({', '.join(repr(a) for a in self.annotations)})"
return (
f"{self.__class__.__name__}("
f"{', '.join(repr(a) for a in self.annotations)})"
)

__repr__ = __str__


class IdentifiableArtefact(AnnotableArtefact):
"""
"""Identifiable Artefact class.
Provides identity to all derived classes. It also provides annotations
to derive classes because it is a subclass of AnnotableArtefact.
Expand All @@ -75,13 +85,18 @@ class IdentifiableArtefact(AnnotableArtefact):

def __str__(self) -> str:
"""Returns a human-friendly description."""
return f"{self.__class__.__name__}({self.id}, {', '.join(repr(a) for a in self.annotations)})"
return (
f"{self.__class__.__name__}"
f"({self.id}, "
f"{', '.join(repr(a) for a in self.annotations)})"
)

__repr__ = __str__


class NameableArtefact(IdentifiableArtefact):
"""
"""Nameable Artefact class.
Provides a name and a description to all derived classes.
Attributes:
Expand All @@ -94,7 +109,8 @@ class NameableArtefact(IdentifiableArtefact):


class VersionableArtefact(NameableArtefact):
"""
"""Versionable Artefact class.
Provides a version to all derived classes.
Attributes:
Expand All @@ -109,7 +125,8 @@ class VersionableArtefact(NameableArtefact):


class MaintainableArtefact(VersionableArtefact):
"""
"""Maintainable Artefact class.
An abstract class to group together primary structural metadata
artefacts that are maintained by an Agency.
Expand All @@ -129,26 +146,32 @@ class MaintainableArtefact(VersionableArtefact):

def __str__(self) -> str:
"""Returns a human-friendly description."""
return f"{self.__class__.__name__}({self.id}, {self.name}, {self.version})"
return (
f"{self.__class__.__name__}"
f"({self.id}, {self.name}, {self.version})"
)

__repr__ = __str__


class Agency(MaintainableArtefact):
"""
Responsible agency for maintaining artefacts such as statistical
classifications, glossaries, structural metadata such as Data and Metadata Structure
"""Agency class.
Responsible agency for maintaining artefacts
such as statistical classifications, glossaries,
structural metadata such as Data and Metadata Structure
Definitions, Concepts and Code lists.
Attributes:
contacts: The contact of the agency.
"""

contacts = Sequence["Contact"]
contacts = Sequence[Contact]


class Item(NameableArtefact):
"""
"""Item class.
The Item is an item of content in an Item Scheme. This may be a
concept in a concept scheme, a code in a codelist, etc.
Expand All @@ -164,7 +187,8 @@ class Item(NameableArtefact):


class ItemScheme(MaintainableArtefact):
"""
"""ItemScheme class.
The descriptive information for an arrangement or division of objects
into groups based on characteristics, which the objects have in common.
Expand Down
7 changes: 2 additions & 5 deletions src/pysdmx/model/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

from msgspec import Struct

from pysdmx.model.__base import ItemScheme
from pysdmx.model.__base import Item, ItemScheme


class Code(Struct, frozen=True, omit_defaults=True):
class Code(Item):
"""A code, such as a country code in the list of ISO 3166 codes.
Codes may have business validity information.
Expand All @@ -37,9 +37,6 @@ class Code(Struct, frozen=True, omit_defaults=True):
valid_to: End of the code's validity period.
"""

id: str
name: Optional[str] = None
description: Optional[str] = None
valid_from: Optional[datetime] = None
valid_to: Optional[datetime] = None

Expand Down
2 changes: 1 addition & 1 deletion src/pysdmx/model/concept.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from datetime import datetime
from enum import Enum
from typing import Iterator, Optional, Sequence, Union
from typing import Optional, Sequence, Union

from msgspec import Struct

Expand Down

0 comments on commit 54d4ef9

Please sign in to comment.