Skip to content

Commit

Permalink
Fix even more ruff-highlighted errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bergercookie committed Aug 11, 2024
1 parent f33b6fa commit 859ebc7
Show file tree
Hide file tree
Showing 23 changed files with 84 additions and 95 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,4 @@ test-tw-gcal-sync.json
/.envrc
.tool-versions
.lvimrc
a
68 changes: 24 additions & 44 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -193,62 +193,42 @@ exclude = []

select = ["ALL"]
ignore = [
# remove them in phases
"ANN001",
"ANN002",
"ANN003",
"ANN101",
"ANN102",
"ANN201",
"ANN202",
"ANN204",
"ANN206",
"ARG001",
"ARG002",
"D100",
"D100",
"D101",
"D101",
"D102",
"S101",
"D102",
"D103",
"D103",
"ANN001",
"ANN202",
"D100",
"FBT001",
"PT009",
"ANN003",
"PGH003",
"N803",
"FBT002",
"FA100",
"TRY003",
"SLF001",
"EM102",
"ARG002",
"D105",
"D107",
"D107",
"D203",
"EM101",
"ARG001",
"D205",
"D213",
"D400",
"D401",
"D415",
"DTZ004",
"E501",
"E712",
"EM101",
"EM102",
"FA100",
"FA102",
"FBT001",
"FBT002",
"INP001",
"N802",
"N803",
"E501",
"SIM118",
"N806",
"PGH003",
"ANN002",
"ANN204",
"N802",
"PLR0913",
"PLR2004",
"PT009",
"RET504",
"RUF012",
"S101",
"S101",
"SIM118",
"SLF001",
"TD002",
"TD003",
"TRY003",
"UP007",
"PLR2004",
"ANN206",
]
exclude = []

Expand Down
9 changes: 4 additions & 5 deletions syncall/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def finish(self) -> None:
self._side_B.finish()

def inserter_to(self, item: Item, helper: SideHelper) -> ID:
"""Inserter.
"""Insert an item using the given side helper.
Other side already has the item, and I'm also inserting it at this side.
"""
Expand All @@ -246,7 +246,7 @@ def inserter_to(self, item: Item, helper: SideHelper) -> ID:
return item_created_id

def updater_to(self, item_id: ID, item: Item, helper: SideHelper):
"""Updater."""
"""Update an item using the given side helper."""
side, _ = self._get_side_instances(helper)
serdes_dir, _ = self._get_serdes_dirs(helper)
logger.info(
Expand All @@ -258,7 +258,7 @@ def updater_to(self, item_id: ID, item: Item, helper: SideHelper):
pickle_dump(item, serdes_dir / item_id)

def deleter_to(self, item_id: ID, helper: SideHelper):
"""Deleter."""
"""Delete an item using the given side helper."""
logger.info(f"[{helper}] Synchronising deleted item, id -> {item_id}...")
side, _ = self._get_side_instances(helper)
side.delete_single_item(item_id)
Expand All @@ -269,8 +269,7 @@ def item_getter_for(self, item_id: ID, helper: SideHelper) -> Item:
"""Item Getter."""
logger.debug(f"Fetching {helper} item for id -> {item_id}")
side, _ = self._get_side_instances(helper)
item = side.get_item(item_id)
return item
return side.get_item(item_id)

def _item_has_update(self, prev_item: Item, new_item: Item, helper: SideHelper) -> bool:
"""Determine whether the item has been updated."""
Expand Down
3 changes: 1 addition & 2 deletions syncall/app_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,8 @@ def determine_app_config_fname(side_A_name: str, side_B_name: str) -> str:
>>> assert determine_app_config_fname("TW", "Google Tasks") == 'tw__google_tasks__configs.yaml'
>>> assert determine_app_config_fname("TW", "Google Calendar") == 'tw__google_calendar__configs.yaml'
"""
config_fname = (
return (
f'{side_A_name.replace(" ", "_").lower()}'
"__"
f'{side_B_name.replace(" ", "_").lower()}__configs.yaml'
)
return config_fname
2 changes: 2 additions & 0 deletions syncall/asana/asana_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

@dataclass
class AsanaTask(Mapping):
"""Represent an Asana task."""

completed: bool
completed_at: datetime.datetime
created_at: datetime.datetime
Expand Down
4 changes: 1 addition & 3 deletions syncall/caldav/caldav_side.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def get_item(self, item_id: ID, use_cached: bool = False):
return item

def _find_todo_by_id_raw(self, item_id: ID) -> caldav.CalendarObjectResource | None:
item = next(
return next(
(
item
for item in calendar_todos(self._calendar)
Expand All @@ -92,8 +92,6 @@ def _find_todo_by_id_raw(self, item_id: ID) -> caldav.CalendarObjectResource | N
None,
)

return item

def _find_todo_by_id(self, item_id: ID) -> dict | None:
raw_item = self._find_todo_by_id_raw(item_id=item_id)
if raw_item:
Expand Down
6 changes: 2 additions & 4 deletions syncall/caldav/caldav_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def icalendar_component(obj: caldav.CalendarObjectResource):
"""The .icalendar_component isn't picked up by linters
"""Get the .icalendar_component isn't picked up by linters
Ignore the warning when accessing it.
"""
Expand All @@ -29,9 +29,7 @@ def _parse_vcategory(vcategory: vCategory) -> Sequence[str]:


def map_ics_to_item(vtodo) -> dict:
"""Utility function that extracts the relevant info from an icalendar_component into a python
dict
"""
"""Extract the relevant info from an icalendar_component into a python dict."""
todo_item = {}
todo_item["id"] = str(vtodo.get("uid"))

Expand Down
7 changes: 2 additions & 5 deletions syncall/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ def decorator(f):

# --asana-task-gid is used to ease development and debugging. It is not currently
# suitable for regular use.
f = _opt_asana_task_gid(hidden=hidden_gid)(f)

return f
return _opt_asana_task_gid(hidden=hidden_gid)(f)

return decorator

Expand Down Expand Up @@ -478,8 +476,7 @@ def decorator(f):
fn_args = d[1:]
f = fn(*fn_args)(f) # type: ignore

f = click.option("-v", "--verbose", count=True)(f)
return f
return click.option("-v", "--verbose", count=True)(f)

return decorator

Expand Down
4 changes: 4 additions & 0 deletions syncall/concrete_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@


class KeyType(Enum):
"""Possible types of keys in an item."""

String = auto()
Date = auto()
Boolean = auto()
Expand All @@ -18,6 +20,8 @@ class KeyType(Enum):

@dataclass
class ItemKey:
"""Key of an item."""

name: str
type: KeyType

Expand Down
3 changes: 1 addition & 2 deletions syncall/google/gcal_side.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ def get_event_time(item: dict, t: str) -> datetime.datetime:
if isinstance(item[t], datetime.datetime):
return item[t]

dt = GCalSide.parse_datetime(item[t][GCalSide.get_date_key(item[t])])
return dt
return GCalSide.parse_datetime(item[t][GCalSide.get_date_key(item[t])])

@staticmethod
def format_datetime(dt: datetime.datetime) -> str:
Expand Down
7 changes: 5 additions & 2 deletions syncall/google/gkeep_side.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@


class GKeepSide(SyncSide):
"""Wrapper class to add/modify/delete todo entries from Google Keep."""

def __init__(
self,
gkeep_user: str,
gkeep_passwd: Optional[str] = None,
gkeep_token: Optional[str] = None,
**kargs,
):
"""Init."""
self._keep: Keep
self._gkeep_user = gkeep_user
self._gkeep_passwd = gkeep_passwd
Expand Down Expand Up @@ -53,11 +56,11 @@ def finish(self):
self._keep.sync()

def _note_has_label(self, note: TopLevelNode, label: Label) -> bool:
"""True if the given Google Keep note has the given label."""
"""Return true if the Google Keep note has the said label."""
return any(label == la for la in note.labels.all())

def _note_has_label_str(self, note: TopLevelNode, label_str: str) -> bool:
"""True if the given Google Keep note has the given label."""
"""Return true if the Google Keep note has the said label."""
return any(label_str == la.name for la in note.labels.all())

def _get_label_by_name(self, label: str) -> Optional[Label]:
Expand Down
2 changes: 1 addition & 1 deletion syncall/google/google_side.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(
self._service = None

def _get_credentials(self):
"""Gets valid user credentials from storage.
"""Get valid user credentials from storage.
If nothing has been stored, or if the stored credentials are invalid,
the OAuth2 flow is completed to obtain the new credentials.
Expand Down
4 changes: 1 addition & 3 deletions syncall/notion/notion_side.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,8 @@ def items_are_identical(
@staticmethod
def find_todos(page_contents: NotionPageContents) -> Sequence[NotionTodoBlock]:
assert page_contents["object"] == "list"
todos = tuple(
return tuple(
NotionTodoBlock.from_raw_item(cast(NotionTodoBlockItem, block))
for block in page_contents["results"]
if NotionTodoBlock.is_todo(block)
)

return todos
2 changes: 2 additions & 0 deletions syncall/notion/notion_todo_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@


class NotionTodoBlock(ConcreteItem):
"""Represent a todo block in Notion."""

def __init__(
self,
is_archived: bool,
Expand Down
2 changes: 1 addition & 1 deletion syncall/taskwarrior/taskwarrior_side.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(
config_overrides: Mapping[str, Any] = {},
**kargs,
):
"""Constructor.
"""Init.
:param tags: Only include tasks that have are tagged using *all* the specified tags.
Also assign these tags to newly added items
Expand Down
12 changes: 12 additions & 0 deletions syncall/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ class TaskwarriorRawItem(TypedDict, total=False):


class GTaskLink(TypedDict):
"""Link part of an item as returned from the Google Tasks Python API on."""

description: str
link: str
type: str # "email"


class GTasksList(TypedDict):
r"""Dict part of a list as returned from the Google Tasks Python API."""

etag: str # ETag of the resource.
id: str # Task list identifier.
kind: str # Type of the resource. This is always "tasks#taskList".
Expand Down Expand Up @@ -267,11 +271,15 @@ class NotionTodoSection(TypedDict):


class NotionTodoBlockItem(NotionRawItem):
"""Todo block item as returned from the Notion Python API."""

to_do: NotionTodoSection


# Page contents as returned from the Notion Python API
class NotionPageContents(TypedDict):
"""Page contents as returned from the Notion Python API."""

object: Literal["list"]
results: list[NotionRawItem]
next_cursor: Any
Expand All @@ -285,6 +293,8 @@ class NotionPageContents(TypedDict):

# Task as returned from Asana API.
class AsanaRawTask(TypedDict):
"""Task as returned from Asana API."""

completed: bool
completed_at: str
created_at: str
Expand All @@ -303,5 +313,7 @@ class AsanaRawTask(TypedDict):

# create a Protocol class for instances that have the __str__ method
class SupportsStr(Protocol):
"""Protocol for instances that have the __str__ method."""

def __str__(self) -> str:
...
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def emit(self, record):


class MockPrefsManager(PrefsManager):
"""Mock the PrefsManager class."""

def __init__(self):
self._conts = {
"kalimera": {"a": 1, "b": 2, "c": [1, 2, 3]},
Expand Down
8 changes: 2 additions & 6 deletions tests/conftest_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ def non_existent_python_path(tmpdir_path, fs_file_default_fname) -> Path:

@pytest.fixture()
def fs_file_empty(tmpdir_path, fs_file_default_fname) -> FilesystemFile:
fs = FilesystemFile(tmpdir_path / fs_file_default_fname)

return fs
return FilesystemFile(tmpdir_path / fs_file_default_fname)


@pytest.fixture()
Expand All @@ -53,9 +51,7 @@ def python_path_with_content(tmpdir_path, fs_file_default_fname) -> Path:

@pytest.fixture()
def fs_file_with_content(python_path_with_content: Path) -> FilesystemFile:
fs = FilesystemFile(python_path_with_content)

return fs
return FilesystemFile(python_path_with_content)


def _create_fs_side(filesystem_root: str):
Expand Down
3 changes: 1 addition & 2 deletions tests/conftest_gkeep.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ def gkeep_list_instance0(gkeep_list0: List) -> List:

@pytest.fixture()
def gkeep_note_empty_instance(gkeep_note_empty: dict) -> MyGKeepNote:
note = MyGKeepNote.from_raw_item(gkeep_note_empty)
return note
return MyGKeepNote.from_raw_item(gkeep_note_empty)


@pytest.fixture()
Expand Down
Loading

0 comments on commit 859ebc7

Please sign in to comment.