From 6333341e3d01aa7294f76758cc67d0c422bcf672 Mon Sep 17 00:00:00 2001 From: Stefan Garlonta Date: Thu, 15 Jun 2023 20:11:58 +0200 Subject: [PATCH] Fix Pylint issues --- pystreamapi/conditions/date.py | 41 +++++++++++++------------ tests/test_date_conditions.py | 2 +- tests/test_date_conditions_type_date.py | 2 +- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/pystreamapi/conditions/date.py b/pystreamapi/conditions/date.py index 4252793..48c4af3 100644 --- a/pystreamapi/conditions/date.py +++ b/pystreamapi/conditions/date.py @@ -64,7 +64,7 @@ def today(): The condition that checks if a datetime is today. :return: A condition that checks if a datetime is today. """ - return lambda d: __datetime.now().date() == d.date() if type(d) == __datetime else \ + return lambda d: __datetime.now().date() == d.date() if isinstance(d, __datetime) else \ __datetime.now().date() == d @@ -75,7 +75,7 @@ def today_utc(): :return: A condition that checks if a datetime is today. """ return lambda d: __datetime.now(__timezone.utc).date() == d.astimezone(__timezone.utc).date() \ - if type(d) == __datetime else __datetime.now(__timezone.utc).date() == d + if isinstance(d, __datetime) else __datetime.now(__timezone.utc).date() == d @@ -84,8 +84,8 @@ def yesterday(): The condition that checks if a datetime is yesterday. :return: A condition that checks if a datetime is yesterday. """ - return lambda d: __datetime.now().date() - __timedelta(days=1) == d.date() if type(d) == \ - __datetime else __datetime.now().date() - __timedelta(days=1) == d + return lambda d: __datetime.now().date() - __timedelta(days=1) == d.date() if \ + isinstance(d, __datetime) else __datetime.now().date() - __timedelta(days=1) == d def yesterday_utc(): @@ -95,8 +95,8 @@ def yesterday_utc(): :return: A condition that checks if a datetime is yesterday. """ return lambda d: __datetime.now(__timezone.utc).date() - __timedelta(days=1) == d.astimezone( - __timezone.utc).date() if type(d) == __datetime else __datetime.now(__timezone.utc).date() \ - - __timedelta(days=1) == d + __timezone.utc).date() if isinstance(d, __datetime) \ + else __datetime.now(__timezone.utc).date() - __timedelta(days=1) == d def tomorrow(): @@ -104,8 +104,8 @@ def tomorrow(): A condition that checks if a datetime is tomorrow. :return: A condition that checks if a datetime is tomorrow. """ - return lambda d: __datetime.now().date() + __timedelta(days=1) == d.date() if type(d) == \ - __datetime else __datetime.now().date() + __timedelta(days=1) == d + return lambda d: __datetime.now().date() + __timedelta(days=1) == d.date() if \ + isinstance(d, __datetime) else __datetime.now().date() + __timedelta(days=1) == d def tomorrow_utc(): @@ -115,8 +115,8 @@ def tomorrow_utc(): :return: A condition that checks if a datetime is tomorrow. """ return lambda d: __datetime.now(__timezone.utc).date() + __timedelta(days=1) == d.astimezone( - __timezone.utc).date() if type(d) == __datetime else __datetime.now(__timezone.utc).date() \ - + __timedelta(days=1) == d + __timezone.utc).date() if isinstance(d, __datetime) \ + else __datetime.now(__timezone.utc).date() + __timedelta(days=1) == d def this_week(): @@ -124,8 +124,9 @@ def this_week(): A condition that checks if a datetime is this week. :return: A condition that checks if a datetime is this week. """ - return lambda d: __datetime.now().date().isocalendar()[1] == d.date().isocalendar()[1] if \ - type(d) == __datetime else __datetime.now().date().isocalendar()[1] == d.isocalendar()[1] + return lambda d: __datetime.now().date().isocalendar()[1] == d.date().isocalendar()[1] \ + if isinstance(d, __datetime) \ + else __datetime.now().date().isocalendar()[1] == d.isocalendar()[1] def this_week_utc(): @@ -135,7 +136,7 @@ def this_week_utc(): :return: A condition that checks if a datetime is this week. """ return lambda d: __datetime.now(__timezone.utc).date().isocalendar()[1] == \ - d.astimezone(__timezone.utc).date().isocalendar()[1] if type(d) == __datetime else \ + d.astimezone(__timezone.utc).date().isocalendar()[1] if isinstance(d, __datetime) else \ __datetime.now(__timezone.utc).date().isocalendar()[1] == d.isocalendar()[1] @@ -145,7 +146,8 @@ def last_week(): :return: A condition that checks if a datetime is last week. """ return lambda d: __datetime.now().date().isocalendar()[1] - 1 == d.date().isocalendar()[1] if \ - type(d) == __datetime else __datetime.now().date().isocalendar()[1] - 1 == d.isocalendar()[1] + isinstance(d, __datetime) else __datetime.now().date().isocalendar()[1] - 1 \ + == d.isocalendar()[1] def last_week_utc(): @@ -155,7 +157,7 @@ def last_week_utc(): :return: A condition that checks if a datetime is last week. """ return lambda d: __datetime.now(__timezone.utc).date().isocalendar()[1] - 1 == \ - d.astimezone(__timezone.utc).date().isocalendar()[1] if type(d) == __datetime else \ + d.astimezone(__timezone.utc).date().isocalendar()[1] if isinstance(d, __datetime) else \ __datetime.now(__timezone.utc).date().isocalendar()[1] - 1 == d.isocalendar()[1] @@ -165,7 +167,8 @@ def next_week(): :return: A condition that checks if a datetime is next week. """ return lambda d: __datetime.now().date().isocalendar()[1] + 1 == d.date().isocalendar()[1] if \ - type(d) == __datetime else __datetime.now().date().isocalendar()[1] + 1 == d.isocalendar()[1] + isinstance(d, __datetime) else __datetime.now().date().isocalendar()[1] + 1 \ + == d.isocalendar()[1] def next_week_utc(): @@ -175,7 +178,7 @@ def next_week_utc(): :return: A condition that checks if a datetime is next week. """ return lambda d: __datetime.now(__timezone.utc).date().isocalendar()[1] + 1 == \ - d.astimezone(__timezone.utc).date().isocalendar()[1] if type(d) == __datetime else \ + d.astimezone(__timezone.utc).date().isocalendar()[1] if isinstance(d, __datetime) else \ __datetime.now(__timezone.utc).date().isocalendar()[1] + 1 == d.isocalendar()[1] @@ -239,7 +242,7 @@ def __check_is_month(d: __datetime, offset: int = 0, tz: __timezone = None): :param tz: The timezone to check against. """ return __datetime.now(tz).date().month + offset == d.astimezone(tz).date().month if \ - type(d) == __datetime else __datetime.now(tz).date().month + offset == d.month + isinstance(d, __datetime) else __datetime.now(tz).date().month + offset == d.month def this_year(): @@ -300,4 +303,4 @@ def __check_is_year(d: __datetime, offset: int = 0, tz: __timezone = None): :param offset: The offset to check against. """ return __datetime.now(tz).date().year + offset == d.astimezone(tz).date().year if \ - type(d) == __datetime else __datetime.now(tz).date().year + offset == d.year + isinstance(d, __datetime) else __datetime.now(tz).date().year + offset == d.year diff --git a/tests/test_date_conditions.py b/tests/test_date_conditions.py index 151af74..6074919 100644 --- a/tests/test_date_conditions.py +++ b/tests/test_date_conditions.py @@ -1,4 +1,4 @@ -# pylint: disable=wildcard-import,too-many-instance-attributes +# pylint: disable=wildcard-import,too-many-instance-attributes,unused-wildcard-import from datetime import datetime, timedelta, timezone from unittest import TestCase diff --git a/tests/test_date_conditions_type_date.py b/tests/test_date_conditions_type_date.py index 8d8d713..77ddd28 100644 --- a/tests/test_date_conditions_type_date.py +++ b/tests/test_date_conditions_type_date.py @@ -1,4 +1,4 @@ -# pylint: disable=wildcard-import,too-many-instance-attributes +# pylint: disable=wildcard-import,too-many-instance-attributes,unused-wildcard-import from datetime import datetime, timedelta, timezone from unittest import TestCase