From 231f09241b5c106bd7311addc69b653ea77735ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Kub=C3=AD=C4=8Dek?= Date: Sat, 8 Feb 2025 14:35:10 +0100 Subject: [PATCH] data_types: fix module by pylint hints --- superfaktura/utils/data_types.py | 49 ++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/superfaktura/utils/data_types.py b/superfaktura/utils/data_types.py index af65e71..b055345 100644 --- a/superfaktura/utils/data_types.py +++ b/superfaktura/utils/data_types.py @@ -1,3 +1,22 @@ +""" +Data Types Module. + +This module provides data types and utilities for working with dates and other data types +in the SuperFaktura API. + +Classes: + - Date: Represents a date in the format YYYY-MM-DD. + - DateTime: Represents a date and time in the format YYYY-MM-DD HH:MM:SS. + +Functions: + - (none) + +Usage: + from superfaktura.utils.data_types import Date, DateTime + date = Date("2022-01-01") + datetime = DateTime("2022-01-01 12:00:00") +""" + from datetime import datetime from typing import Optional @@ -5,6 +24,22 @@ import json class Date: + """ + Date Class. + + This class represents a date in the format YYYY-MM-DD. + + Attributes: + - date (str): The date in the format YYYY-MM-DD. + + Methods: + - __str__: Returns the date as a string. + + Usage: + date = Date("2022-01-01") + print(date) # Output: 2022-01-01 + """ + def __init__(self, date_str: Optional[str] = None): """ Creates a Date instance that supports typing and validation for the format YYYY-MM-DD. @@ -56,6 +91,20 @@ class Date: class DateEncoder(json.JSONEncoder): + """ + Date Encoder Class. + + This class is a custom JSON encoder that converts Date objects to strings. + + Methods: + - default: Encodes a Date object as a string. + + Usage: + encoder = DateEncoder() + date = Date("2022-01-01") + json_string = json.dumps(date, cls=encoder) + """ + def default(self, o): if isinstance(o, Date): return o.to_json()