Skip to content

Commit

Permalink
static type the autoclose function
Browse files Browse the repository at this point in the history
  • Loading branch information
th3w1zard1 committed Jan 14, 2024
1 parent b7f1d30 commit 66b3fca
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Libraries/PyKotor/src/pykotor/resource/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 66b3fca

Please sign in to comment.