Skip to content

Commit

Permalink
pylint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bgalek committed Jan 18, 2024
1 parent 72b5fee commit cf8c2cb
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 75 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/pylint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,4 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
- name: Analysing the code with pylint
run: pylint $(git ls-files '*.py')
- uses: marian-code/python-lint-annotate@v3
7 changes: 5 additions & 2 deletions _tests/test_dated_entries_group.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import unittest
from unittest import TestCase

from dated_entries_group import DatedEntriesGroup, InvalidDateError, \
Expand Down Expand Up @@ -162,11 +163,13 @@ def test_falseness_of_dated_entries_group(self):
self.assertEqual(len(another_day.known_entries_from_this_day), 0)
self.assertFalse(another_day.known_entries_from_this_day)

@unittest.skip("not yet implemented")
def test_no_duplicate_entries_created(self):
"""
DatedEntriesGroup should return the already existing entry if it is known, instead of creating a duplicate.
"""
pass
self.assertEqual(True, True)

@unittest.skip("not yet implemented")
def test_retrieve_known_entries(self):
pass
self.assertEqual(True, True)
1 change: 1 addition & 0 deletions _tests/test_dated_entry.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from unittest import TestCase

from dated_entry import Time, slice_quotes, DatedEntry, IsNotTimeError


Expand Down
1 change: 1 addition & 0 deletions _tests/test_errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from unittest import TestCase

import errors


Expand Down
4 changes: 1 addition & 3 deletions _tests/test_mood.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import logging
from unittest import TestCase

import utils
from entry.mood import Moodverse, MoodGroup, Mood, MoodNotFoundError
from typing import List
from entry.mood import Moodverse, MoodGroup


# noinspection SpellCheckingInspection
Expand Down
4 changes: 2 additions & 2 deletions _tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os.path
from unittest import TestCase
import logging
from unittest import TestCase

import utils


Expand Down
48 changes: 19 additions & 29 deletions dated_entries_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@
"""
from __future__ import annotations

from typing import Optional
import re
import logging
import re

import dated_entry
import entry.mood
import errors
from typing import List
import utils
from dated_entry import DatedEntry
from entry.mood import Moodverse
import utils


class DatedEntryMissingError(utils.CustomException):
Expand Down Expand Up @@ -50,11 +47,10 @@ def __new__(cls, string: str):
# Check if an instance for the given date already exists
if string in cls._instances:
return cls._instances[string]
else:
# If not, create a new instance
instance = super(Date, cls).__new__(cls)
cls._instances[string] = instance
return instance
# If not, create a new instance
instance = super(Date, cls).__new__(cls)
cls._instances[string] = instance
return instance

def __init__(self, string: str):
"""
Expand Down Expand Up @@ -92,8 +88,7 @@ def __eq__(self, other: 'Date') -> bool:
return all((other.year == self.year,
other.month == self.month,
other.day == self.day))
else:
super().__eq__(other)
super().__eq__(other)

@property
def year(self):
Expand Down Expand Up @@ -124,11 +119,10 @@ def __new__(cls, date: str, current_mood_set: Moodverse = Moodverse()):
# Check if an instance for the given date already exists
if date in cls._instances:
return cls._instances[date]
else:
# If not, create a new instance
instance = super(DatedEntriesGroup, cls).__new__(cls)
cls._instances[date] = instance
return instance
# If not, create a new instance
instance = super(DatedEntriesGroup, cls).__new__(cls)
cls._instances[date] = instance
return instance

def __init__(self, date, current_mood_set: Moodverse = Moodverse()):
"""
Expand All @@ -148,9 +142,8 @@ def __init__(self, date, current_mood_set: Moodverse = Moodverse()):
raise InvalidDateError(msg)

# All good - initialise
else:
self.__known_entries_for_this_date: dict[str, DatedEntry] = {}
self.__known_moods: Moodverse = current_mood_set
self.__known_entries_for_this_date: dict[str, DatedEntry] = {}
self.__known_moods: Moodverse = current_mood_set

def create_dated_entry_from_row(self,
line: dict[str, str]) -> dated_entry.DatedEntry:
Expand All @@ -169,9 +162,8 @@ def create_dated_entry_from_row(self,
except KeyError:
raise IncompleteDataRow(key)
# is it empty then, maybe?
else:
if not line[key]:
raise IncompleteDataRow(key)
if not line[key]:
raise IncompleteDataRow(key)

# Check if there's already an object with this time
if line["time"] in self.__known_entries_for_this_date:
Expand All @@ -189,9 +181,8 @@ def create_dated_entry_from_row(self,
)
except ValueError:
raise ValueError
else:
self.__known_entries_for_this_date[str(this_entry.uid)] = this_entry
return this_entry
self.__known_entries_for_this_date[str(this_entry.uid)] = this_entry
return this_entry

def access_dated_entry(self, time: str) -> DatedEntry:
"""
Expand All @@ -206,9 +197,8 @@ def access_dated_entry(self, time: str) -> DatedEntry:
msg = ErrorMsg.print(ErrorMsg.OBJECT_NOT_FOUND, time)
self.__logger.warning(msg)
raise DatedEntryMissingError(msg)
else:
self.__logger.debug(ErrorMsg.print(ErrorMsg.OBJECT_FOUND, time))
return ref
self.__logger.debug(ErrorMsg.print(ErrorMsg.OBJECT_FOUND, time))
return ref

@property
def known_entries_from_this_day(self):
Expand Down
4 changes: 2 additions & 2 deletions dated_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import re
from typing import Match

from entry.mood import Moodverse
from config import options
import errors
import utils
from config import options
from entry.mood import Moodverse

# Adding DatedEntry-specific options in global_settings
dated_entry_settings = options.arg_console.add_argument_group(
Expand Down
19 changes: 7 additions & 12 deletions entry/mood.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ def __expand_moodset_with_customs(self, moods_to_process: dict[str, List[str]])
self.__logger.warning(msg)
raise MoodNotFoundError(msg)
# Go through each mood in this mood group - e.g. rad - and transfer them in the form of Mood objects
else:
for mood in mood_group_to_transfer:
self.__mood_set[expected_mood_group].create_mood(mood)
for mood in mood_group_to_transfer:
self.__mood_set[expected_mood_group].create_mood(mood)

def get_mood(self, value_to_check: str) -> Optional['Mood']:
"""
Expand Down Expand Up @@ -140,8 +139,7 @@ class AbstractMood:
def __init__(self, value):
if not value or isinstance(value, str) is False:
raise ValueError
else:
self.__name = value
self.__name = value

@property
def name(self) -> str:
Expand All @@ -153,8 +151,7 @@ def __str__(self) -> str:
def __eq__(self, other) -> bool:
if isinstance(other, str):
return str(self) == other
else:
return super().__eq__(other) # of object object
return super().__eq__(other) # of object object


class MoodGroup(AbstractMood):
Expand Down Expand Up @@ -217,8 +214,7 @@ def __getitem__(self, item: str) -> 'Mood':
"""
if item in self.__known_moods:
return self.__known_moods[item]
else:
raise KeyError
raise KeyError

def __eq__(self, other: List[str]) -> bool:
"""
Expand All @@ -232,9 +228,8 @@ def __eq__(self, other: List[str]) -> bool:
# I'm not sure why, but set() instead of pure array makes sure that the order is irrelevant
# therefore ["nice", "good"] == ["good", "nice"] is Truthy, as expected
return set([str(obj) for obj in self.known_moods]) == set(other)
else:
# Call the superclass' __eq__ for any other comparison
return super().__eq__(other)
# Call the superclass' __eq__ for any other comparison
return super().__eq__(other)


class Mood(AbstractMood):
Expand Down
3 changes: 1 addition & 2 deletions errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,4 @@ def print(message: str, *args: str) -> Optional[str]:
f"Expected {expected_args} arguments for \"{message}\", but got {len(args)} instead."
)
return None
else:
return message.format(*args)
return message.format(*args)
24 changes: 11 additions & 13 deletions librarian.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
import logging

import dated_entries_group
from config import options
from entry.mood import Moodverse
import errors
import utils
from config import options
from dated_entries_group import DatedEntriesGroup
from entry.mood import Moodverse

# Adding Librarian-specific options in global_settings
librarian_settings = options.arg_console.add_argument_group(
Expand Down Expand Up @@ -304,17 +304,15 @@ def __process_line(self, line: dict[str]) -> bool:
msg = ErrorMsg.print(ErrorMsg.FILE_INCOMPLETE, str(line))
self.__logger.warning(msg)
raise MissingValuesInRowError(msg)
else:
# Let DatedEntriesGroup handle the rest and increment the counter (True == 1)
try:
self.access_date(line["full_date"]).create_dated_entry_from_row(line)
except (dated_entries_group.TriedCreatingDuplicateDatedEntryError,
dated_entries_group.IncompleteDataRow,
dated_entries_group.InvalidDateError,
ValueError):
return False
else:
return True
# Let DatedEntriesGroup handle the rest and increment the counter (True == 1)
try:
self.access_date(line["full_date"]).create_dated_entry_from_row(line)
except (dated_entries_group.TriedCreatingDuplicateDatedEntryError,
dated_entries_group.IncompleteDataRow,
dated_entries_group.InvalidDateError,
ValueError):
return False
return True

def access_date(self, target_date: str) -> DatedEntriesGroup:
"""
Expand Down
6 changes: 3 additions & 3 deletions utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""
Contains universally useful functions
"""
import re
import os
import logging
import os
import re

import errors


Expand Down Expand Up @@ -65,4 +66,3 @@ def expand_path(path):
os.path.expandvars(path)
)
)

0 comments on commit cf8c2cb

Please sign in to comment.