Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ reportCallInDefaultInitializer = false
reportExplicitAny = false
reportImplicitOverride = false
reportImplicitStringConcatenation = false
reportInvalidAbstractMethod = false
reportMissingParameterType = false
reportMissingTypeArgument = false
reportMissingTypeStubs = false
Expand Down
3 changes: 2 additions & 1 deletion src/usethis/_file/ini/io_.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import configparser
import re
from abc import ABCMeta
from typing import TYPE_CHECKING

from configupdater import ConfigUpdater as INIDocument
Expand Down Expand Up @@ -38,7 +39,7 @@
)


class INIFileManager(KeyValueFileManager):
class INIFileManager(KeyValueFileManager, metaclass=ABCMeta):
_content_by_path: ClassVar[dict[Path, INIDocument | None]] = {}

def __enter__(self) -> Self:
Expand Down
3 changes: 2 additions & 1 deletion src/usethis/_file/toml/io_.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import copy
import re
from abc import ABCMeta
from typing import TYPE_CHECKING, Any

import tomlkit.api
Expand Down Expand Up @@ -42,7 +43,7 @@
from usethis._io import Key


class TOMLFileManager(KeyValueFileManager):
class TOMLFileManager(KeyValueFileManager, metaclass=ABCMeta):
"""An abstract class for managing TOML files."""

_content_by_path: ClassVar[dict[Path, TOMLDocument | None]] = {}
Expand Down
3 changes: 2 additions & 1 deletion src/usethis/_file/yaml/io_.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import copy
import re
from abc import ABCMeta
from contextlib import contextmanager
from dataclasses import dataclass
from io import StringIO
Expand Down Expand Up @@ -44,7 +45,7 @@
from usethis._io import Key


class YAMLFileManager(KeyValueFileManager):
class YAMLFileManager(KeyValueFileManager, metaclass=ABCMeta):
"""An abstract class for managing YAML files."""

_content_by_path: ClassVar[dict[Path, YAMLDocument | None]] = {}
Expand Down
6 changes: 3 additions & 3 deletions src/usethis/_io.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import re
from abc import abstractmethod
from abc import ABCMeta, abstractmethod
from typing import TYPE_CHECKING, Generic, TypeAlias, TypeVar

from typing_extensions import assert_never
Expand Down Expand Up @@ -29,7 +29,7 @@ class UnexpectedFileIOError(UsethisError, IOError):
"""Raised when an unexpected attempt is made to read or write the pyproject.toml file."""


class UsethisFileManager(Generic[DocumentT]):
class UsethisFileManager(Generic[DocumentT], metaclass=ABCMeta):
"""Manages file access with deferred writes using a context manager.

This class implements the Command Pattern, encapsulating file operations. It defers
Expand Down Expand Up @@ -180,7 +180,7 @@ def unlock(self) -> None:
Key: TypeAlias = str | re.Pattern[str]


class KeyValueFileManager(UsethisFileManager, Generic[DocumentT]):
class KeyValueFileManager(UsethisFileManager, Generic[DocumentT], metaclass=ABCMeta):
"""A manager for files which store (at least some) values in key-value mappings."""

@abstractmethod
Expand Down
4 changes: 2 additions & 2 deletions src/usethis/_tool/spec.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from abc import abstractmethod
from abc import ABCMeta, abstractmethod
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Protocol

Expand Down Expand Up @@ -42,7 +42,7 @@ class ToolMeta:
url: str | None = None # For documentation purposes


class ToolSpec(Protocol):
class ToolSpec(Protocol, metaclass=ABCMeta):
@property
@abstractmethod
def meta(self) -> ToolMeta: ...
Expand Down
24 changes: 24 additions & 0 deletions tests/usethis/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ class MyUsethisFileManager(UsethisFileManager):
def relative_path(self) -> Path:
return Path("pyproject.toml")

def _dump_content(self) -> str:
raise NotImplementedError

def _parse_content(self, content: str) -> None:
raise NotImplementedError

with change_cwd(tmp_path):
manager = MyUsethisFileManager()

Expand All @@ -30,6 +36,12 @@ class MyUsethisFileManager(UsethisFileManager):
def relative_path(self) -> Path:
return Path("pyproject.toml")

def _dump_content(self) -> str:
raise NotImplementedError

def _parse_content(self, content: str) -> None:
raise NotImplementedError

manager = MyUsethisFileManager()
other_manager = MyUsethisFileManager()

Expand All @@ -46,6 +58,12 @@ class MyUsethisFileManager(UsethisFileManager):
def relative_path(self) -> Path:
return Path("pyproject.toml")

def _dump_content(self) -> str:
raise NotImplementedError

def _parse_content(self, content: str) -> None:
raise NotImplementedError

manager = MyUsethisFileManager()
other_manager = object()

Expand All @@ -63,6 +81,12 @@ class MyUsethisFileManager(UsethisFileManager):
def relative_path(self) -> Path:
return Path("pyproject.toml")

def _dump_content(self) -> str:
raise NotImplementedError

def _parse_content(self, content: str) -> None:
raise NotImplementedError

with change_cwd(tmp_path):
manager = MyUsethisFileManager()

Expand Down
Loading