Skip to content

Commit 93c23d1

Browse files
enable reportInvalidAbstractMethod in basedpyright (#1442)
1 parent f158b2a commit 93c23d1

7 files changed

Lines changed: 35 additions & 9 deletions

File tree

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ reportCallInDefaultInitializer = false
213213
reportExplicitAny = false
214214
reportImplicitOverride = false
215215
reportImplicitStringConcatenation = false
216-
reportInvalidAbstractMethod = false
217216
reportMissingParameterType = false
218217
reportMissingTypeArgument = false
219218
reportPrivateUsage = false

src/usethis/_file/ini/io_.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import configparser
44
import re
5+
from abc import ABCMeta
56
from typing import TYPE_CHECKING
67

78
from configupdater import ConfigUpdater as INIDocument
@@ -38,7 +39,7 @@
3839
)
3940

4041

41-
class INIFileManager(KeyValueFileManager):
42+
class INIFileManager(KeyValueFileManager, metaclass=ABCMeta):
4243
_content_by_path: ClassVar[dict[Path, INIDocument | None]] = {}
4344

4445
def __enter__(self) -> Self:

src/usethis/_file/toml/io_.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import copy
44
import re
5+
from abc import ABCMeta
56
from typing import TYPE_CHECKING, Any
67

78
import tomlkit.api
@@ -42,7 +43,7 @@
4243
from usethis._io import Key
4344

4445

45-
class TOMLFileManager(KeyValueFileManager):
46+
class TOMLFileManager(KeyValueFileManager, metaclass=ABCMeta):
4647
"""An abstract class for managing TOML files."""
4748

4849
_content_by_path: ClassVar[dict[Path, TOMLDocument | None]] = {}

src/usethis/_file/yaml/io_.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import copy
44
import re
5+
from abc import ABCMeta
56
from contextlib import contextmanager
67
from dataclasses import dataclass
78
from io import StringIO
@@ -44,7 +45,7 @@
4445
from usethis._io import Key
4546

4647

47-
class YAMLFileManager(KeyValueFileManager):
48+
class YAMLFileManager(KeyValueFileManager, metaclass=ABCMeta):
4849
"""An abstract class for managing YAML files."""
4950

5051
_content_by_path: ClassVar[dict[Path, YAMLDocument | None]] = {}

src/usethis/_io.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import re
4-
from abc import abstractmethod
4+
from abc import ABCMeta, abstractmethod
55
from typing import TYPE_CHECKING, Generic, TypeAlias, TypeVar
66

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

3131

32-
class UsethisFileManager(Generic[DocumentT]):
32+
class UsethisFileManager(Generic[DocumentT], metaclass=ABCMeta):
3333
"""Manages file access with deferred writes using a context manager.
3434
3535
This class implements the Command Pattern, encapsulating file operations. It defers
@@ -180,7 +180,7 @@ def unlock(self) -> None:
180180
Key: TypeAlias = str | re.Pattern[str]
181181

182182

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

186186
@abstractmethod

src/usethis/_tool/spec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from abc import abstractmethod
3+
from abc import ABCMeta, abstractmethod
44
from dataclasses import dataclass, field
55
from typing import TYPE_CHECKING, Protocol
66

@@ -42,7 +42,7 @@ class ToolMeta:
4242
url: str | None = None # For documentation purposes
4343

4444

45-
class ToolSpec(Protocol):
45+
class ToolSpec(Protocol, metaclass=ABCMeta):
4646
@property
4747
@abstractmethod
4848
def meta(self) -> ToolMeta: ...

tests/usethis/test_io.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ class MyUsethisFileManager(UsethisFileManager):
1313
def relative_path(self) -> Path:
1414
return Path("pyproject.toml")
1515

16+
def _dump_content(self) -> str:
17+
raise NotImplementedError
18+
19+
def _parse_content(self, content: str) -> None:
20+
raise NotImplementedError
21+
1622
with change_cwd(tmp_path):
1723
manager = MyUsethisFileManager()
1824

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

39+
def _dump_content(self) -> str:
40+
raise NotImplementedError
41+
42+
def _parse_content(self, content: str) -> None:
43+
raise NotImplementedError
44+
3345
manager = MyUsethisFileManager()
3446
other_manager = MyUsethisFileManager()
3547

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

61+
def _dump_content(self) -> str:
62+
raise NotImplementedError
63+
64+
def _parse_content(self, content: str) -> None:
65+
raise NotImplementedError
66+
4967
manager = MyUsethisFileManager()
5068
other_manager = object()
5169

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

84+
def _dump_content(self) -> str:
85+
raise NotImplementedError
86+
87+
def _parse_content(self, content: str) -> None:
88+
raise NotImplementedError
89+
6690
with change_cwd(tmp_path):
6791
manager = MyUsethisFileManager()
6892

0 commit comments

Comments
 (0)