From c04ac82016393feeb5d52477a01561c339e44bb8 Mon Sep 17 00:00:00 2001 From: dgw Date: Mon, 12 Aug 2024 20:10:44 -0700 Subject: [PATCH 1/3] dev-requirements: types-pkg-resources is deprecated `pkg_resources` itself is typed in setuptools>=71.1, negating the need to install type stubs. --- dev-requirements.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 From 04fca7abbe4d6a4141ac4810371db4f3ea5a964f Mon Sep 17 00:00:00 2001 From: dgw Date: Mon, 12 Aug 2024 20:26:23 -0700 Subject: [PATCH 2/3] tools.memories: SopelIdentifierMemory.update() override is intentional mypy has to be told this explicitly, which means a new "runtime" dependency/import that only has to do with type-checking... because decorator evaluation can't be deferred like annotations can. Sigh. --- pyproject.toml | 1 + sopel/tools/memories.py | 3 +++ 2 files changed, 4 insertions(+) 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/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. From c8802f7f61e9b11d52bae225fb0dc66c471be9da Mon Sep 17 00:00:00 2001 From: dgw Date: Mon, 12 Aug 2024 20:31:47 -0700 Subject: [PATCH 3/3] tools: fix union-attr type-check errors in OutputRedirect class I'm very glad this is deprecated. The only reason I'm bothering to fix this is because we can't remove it from the 8.0.x maintenance branch. --- sopel/tools/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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()