From 66b3fca3c73dd41d64159e9d5ad1374bf8b3ef81 Mon Sep 17 00:00:00 2001 From: Benjamin Auquite Date: Sun, 14 Jan 2024 01:15:42 -0600 Subject: [PATCH] static type the autoclose function --- Libraries/PyKotor/src/pykotor/resource/type.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Libraries/PyKotor/src/pykotor/resource/type.py b/Libraries/PyKotor/src/pykotor/resource/type.py index 1942ec8aa..2f1383a9d 100644 --- a/Libraries/PyKotor/src/pykotor/resource/type.py +++ b/Libraries/PyKotor/src/pykotor/resource/type.py @@ -4,7 +4,7 @@ import os import uuid from enum import Enum -from typing import Iterable, NamedTuple, Union +from typing import Callable, Iterable, NamedTuple, TypeVar, Union from xml.etree.ElementTree import ParseError from pykotor.common.stream import BinaryReader, BinaryWriter @@ -304,11 +304,11 @@ def from_extension( ResourceType.from_invalid(extension=lower_ext), ) - -def autoclose(func): - def _autoclose(self: ResourceReader | ResourceWriter, auto_close: bool = True): +R = TypeVar("R") +def autoclose(func: Callable[..., R]) -> Callable[..., R]: + def _autoclose(self: ResourceReader | ResourceWriter, auto_close: bool = True) -> R: # noqa: FBT002, FBT001 try: - resource = func(self, auto_close) + resource: R = func(self, auto_close) except (OSError, ParseError, ValueError, IndexError, StopIteration) as e: msg = "Tried to load an unsupported or corrupted file." raise ValueError(msg) from e