diff --git a/dev-requirements.txt b/dev-requirements.txt index 39c25f980..0224d4df2 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -22,7 +22,9 @@ sphinx-rfcsection~=0.1.1 vcrpy @ git+https://github.com/sopel-irc/vcrpy@uncap-urllib3 # type check mypy>=1.3,<2 +# for `pkg_resources`; first version in which it's typed +# we don't use `pkg_resources` directly, but mypy still cares +setuptools>=71.1 sqlalchemy[mypy]>=1.4,<1.5 -types-pkg-resources~=0.1.3 types-pytz types-requests>=2,<3 diff --git a/pyproject.toml b/pyproject.toml index bc7dc8e49..2e1ccbce6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,6 +52,7 @@ dependencies = [ "importlib_metadata>=3.6", "packaging>=23.2", "sopel-help>=0.4.0", + "typing_extensions>=4.4", # for @typing.override, added in py3.12 ] [project.urls] diff --git a/sopel/tools/__init__.py b/sopel/tools/__init__.py index f391f0005..8fcd13c6a 100644 --- a/sopel/tools/__init__.py +++ b/sopel/tools/__init__.py @@ -160,7 +160,7 @@ def write(self, string): :param str string: the string to write """ - if not self.quiet: + if not self.quiet and sys.__stderr__ and sys.__stdout__: try: if self.stderr: sys.__stderr__.write(string) @@ -179,9 +179,9 @@ def write(self, string): def flush(self): """Flush the file writing buffer.""" - if self.stderr: + if self.stderr and sys.__stderr__: sys.__stderr__.flush() - else: + elif sys.__stdout__: sys.__stdout__.flush() diff --git a/sopel/tools/memories.py b/sopel/tools/memories.py index f38c51864..1fb2b0b2a 100644 --- a/sopel/tools/memories.py +++ b/sopel/tools/memories.py @@ -10,6 +10,8 @@ import threading from typing import Any, Optional, TYPE_CHECKING, Union +from typing_extensions import override + from .identifiers import Identifier, IdentifierFactory if TYPE_CHECKING: @@ -259,6 +261,7 @@ def pop(self, key: str, default=_NO_DEFAULT): return super().pop(self._make_key(key)) return super().pop(self._make_key(key), default) + @override def update(self, maybe_mapping=tuple()): """Update this ``SopelIdentifierMemory`` with key-value pairs.