mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-01-27 17:33:13 +08:00
fixes for latest pylint update
This commit is contained in:
parent
46bef89fc8
commit
200d7946c8
@ -3995,26 +3995,26 @@
|
||||
"assets/src/ba_data/python/ba/_generated/__init__.py": "https://files.ballistica.net/cache/ba1/ee/e8/cad05aa531c7faf7ff7b96db7f6e",
|
||||
"assets/src/ba_data/python/ba/_generated/enums.py": "https://files.ballistica.net/cache/ba1/b2/e5/0ee0561e16257a32830645239f34",
|
||||
"ballisticacore-windows/Generic/BallisticaCore.ico": "https://files.ballistica.net/cache/ba1/89/c0/e32c7d2a35dc9aef57cc73b0911a",
|
||||
"build/prefab/full/linux_arm64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/a5/92/92aeec83f5d8f95db1bccca613ff",
|
||||
"build/prefab/full/linux_arm64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/8a/ff/6b2173474f74f98a0526e51476de",
|
||||
"build/prefab/full/linux_arm64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/9c/cf/8f2c5f3365f53ec3a6735e2be6be",
|
||||
"build/prefab/full/linux_arm64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/7e/f6/c9e8f088e5531b072ef3a262ac10",
|
||||
"build/prefab/full/linux_x86_64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/fd/29/6bcaef9c148e5372c54bebe2d05d",
|
||||
"build/prefab/full/linux_x86_64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/b8/12/c0e7299e3a57cff77016255acdee",
|
||||
"build/prefab/full/linux_x86_64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/e4/ca/cfbda182fd525a8b9acacb5b5722",
|
||||
"build/prefab/full/linux_x86_64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/07/ed/139797a46be28cd21b9f547d44b8",
|
||||
"build/prefab/full/mac_arm64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/a6/bf/b0db75eda2bf6f15a63660a54ed4",
|
||||
"build/prefab/full/mac_arm64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/e1/81/09912802880ec45a8464d8e52cda",
|
||||
"build/prefab/full/mac_arm64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/ef/b9/bca5de5cfe1353bf6946e7d8900b",
|
||||
"build/prefab/full/mac_arm64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/2a/89/5d2e0e0f01d65854040a3047b8a7",
|
||||
"build/prefab/full/mac_x86_64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/f2/8a/7de86a47c5e361e4551afeada214",
|
||||
"build/prefab/full/mac_x86_64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/85/94/5dd16ce67c9085eff7ddff8f8328",
|
||||
"build/prefab/full/mac_x86_64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/20/b3/e58610e3671e9f7ca43495c6d0f4",
|
||||
"build/prefab/full/mac_x86_64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/95/cd/b0e50718cb24f28f8644fb521f37",
|
||||
"build/prefab/full/windows_x86_gui/debug/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/3d/13/3724b21a9cc992bf0a122334892c",
|
||||
"build/prefab/full/windows_x86_gui/release/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/c3/34/3a0c220fe8ea2ed6d1bd1fcf66b1",
|
||||
"build/prefab/full/windows_x86_server/debug/dist/BallisticaCoreHeadless.exe": "https://files.ballistica.net/cache/ba1/e6/82/3ed7bc3aff3da974f9c12ae1560f",
|
||||
"build/prefab/full/windows_x86_server/release/dist/BallisticaCoreHeadless.exe": "https://files.ballistica.net/cache/ba1/ca/f0/d9e7b0b303d579b988d0b5934156",
|
||||
"build/prefab/full/linux_arm64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/73/4e/9032c516e70eee65596d7fe806ec",
|
||||
"build/prefab/full/linux_arm64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/7d/2b/fd4ce5cae4687bb9da779cb13131",
|
||||
"build/prefab/full/linux_arm64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/8b/9c/6032b711bbba319bea660e55da0c",
|
||||
"build/prefab/full/linux_arm64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/ac/82/f9506e68ecf3fca2622aec945940",
|
||||
"build/prefab/full/linux_x86_64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/8d/b2/711860820f8d440c82ec82f08d06",
|
||||
"build/prefab/full/linux_x86_64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/fb/fa/832e958d7bbefaf9a5db1af0d86f",
|
||||
"build/prefab/full/linux_x86_64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/d8/ba/f7b0862f2330d42c02e5ed70f02c",
|
||||
"build/prefab/full/linux_x86_64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/fe/a0/f6614584daeead31299af53dc5d5",
|
||||
"build/prefab/full/mac_arm64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/8e/80/97d7f7a9101fd5c23e8d7276fa0c",
|
||||
"build/prefab/full/mac_arm64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/22/78/85498b94fe3a57f729d452e92fc8",
|
||||
"build/prefab/full/mac_arm64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/ab/57/ac71a57a09557fda0d0449c090f3",
|
||||
"build/prefab/full/mac_arm64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/42/d7/55a58a777db03d15c4e695d2bfd9",
|
||||
"build/prefab/full/mac_x86_64_gui/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/9f/a4/8bfc34f0140430a439c4ff27c797",
|
||||
"build/prefab/full/mac_x86_64_gui/release/ballisticacore": "https://files.ballistica.net/cache/ba1/88/35/9be33899b777146d23e1026d14b0",
|
||||
"build/prefab/full/mac_x86_64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/fa/34/f6cfc1fb05dc35ccccb54ac1010b",
|
||||
"build/prefab/full/mac_x86_64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/30/c4/e646b6fb9064bac03449a03398b4",
|
||||
"build/prefab/full/windows_x86_gui/debug/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/76/6b/e257150ce7eefb25e87de8460428",
|
||||
"build/prefab/full/windows_x86_gui/release/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/b9/d5/1f46d4ed1d2fcf973c1172d88956",
|
||||
"build/prefab/full/windows_x86_server/debug/dist/BallisticaCoreHeadless.exe": "https://files.ballistica.net/cache/ba1/87/24/5ba20247eb4fb38d2dde7aee869f",
|
||||
"build/prefab/full/windows_x86_server/release/dist/BallisticaCoreHeadless.exe": "https://files.ballistica.net/cache/ba1/65/a2/c3e61796608b2a8bad0928b1d071",
|
||||
"build/prefab/lib/linux_arm64_gui/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/3b/0c/2f4061ab877d415a1c30e0e736db",
|
||||
"build/prefab/lib/linux_arm64_gui/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/3c/5a/2b0714af254c64954ccfe51c70b3",
|
||||
"build/prefab/lib/linux_arm64_server/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/1f/ae/c8a885b1a1868b6846b606cdb456",
|
||||
@ -4031,14 +4031,14 @@
|
||||
"build/prefab/lib/mac_x86_64_gui/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/44/df/efb51d1c226eac613d48e2cbf0b8",
|
||||
"build/prefab/lib/mac_x86_64_server/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/1c/f6/357fe951c86c9fc5b1b737cd91ae",
|
||||
"build/prefab/lib/mac_x86_64_server/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/04/17/e2de0ab5df6b938d828e8662ce6d",
|
||||
"build/prefab/lib/windows/Debug_Win32/BallisticaCoreGenericInternal.lib": "https://files.ballistica.net/cache/ba1/43/12/99b9029b31f9abcede32734e9a83",
|
||||
"build/prefab/lib/windows/Debug_Win32/BallisticaCoreGenericInternal.pdb": "https://files.ballistica.net/cache/ba1/f0/27/523ae5d573666078314cbbd988b1",
|
||||
"build/prefab/lib/windows/Debug_Win32/BallisticaCoreHeadlessInternal.lib": "https://files.ballistica.net/cache/ba1/41/bb/1326d20b151d47d67969d4525e4a",
|
||||
"build/prefab/lib/windows/Debug_Win32/BallisticaCoreHeadlessInternal.pdb": "https://files.ballistica.net/cache/ba1/77/3f/6e98ac94c728a0f210b8ce05c418",
|
||||
"build/prefab/lib/windows/Release_Win32/BallisticaCoreGenericInternal.lib": "https://files.ballistica.net/cache/ba1/90/28/8c0aec847a6ebb6e2977e7b50d21",
|
||||
"build/prefab/lib/windows/Release_Win32/BallisticaCoreGenericInternal.pdb": "https://files.ballistica.net/cache/ba1/65/fc/f7c1c6c6208814d721687fa08c5f",
|
||||
"build/prefab/lib/windows/Release_Win32/BallisticaCoreHeadlessInternal.lib": "https://files.ballistica.net/cache/ba1/a7/6b/148a238b89c17790b9dedc481031",
|
||||
"build/prefab/lib/windows/Release_Win32/BallisticaCoreHeadlessInternal.pdb": "https://files.ballistica.net/cache/ba1/41/9d/61822652055f9319630ea3611cad",
|
||||
"build/prefab/lib/windows/Debug_Win32/BallisticaCoreGenericInternal.lib": "https://files.ballistica.net/cache/ba1/69/dc/6fc1614b2548c6ac76c9e891c2e2",
|
||||
"build/prefab/lib/windows/Debug_Win32/BallisticaCoreGenericInternal.pdb": "https://files.ballistica.net/cache/ba1/c2/1b/263c5e001c6891d774d941f0bdfd",
|
||||
"build/prefab/lib/windows/Debug_Win32/BallisticaCoreHeadlessInternal.lib": "https://files.ballistica.net/cache/ba1/7b/3a/f77ffca8d7c45b859d1e48c1b468",
|
||||
"build/prefab/lib/windows/Debug_Win32/BallisticaCoreHeadlessInternal.pdb": "https://files.ballistica.net/cache/ba1/88/15/1aa07f986d0bf7dac9a1f39635f2",
|
||||
"build/prefab/lib/windows/Release_Win32/BallisticaCoreGenericInternal.lib": "https://files.ballistica.net/cache/ba1/4b/e1/646d3095ab442e0b18d4c0de9689",
|
||||
"build/prefab/lib/windows/Release_Win32/BallisticaCoreGenericInternal.pdb": "https://files.ballistica.net/cache/ba1/0f/fe/034c116781ddfe6cc89ada030056",
|
||||
"build/prefab/lib/windows/Release_Win32/BallisticaCoreHeadlessInternal.lib": "https://files.ballistica.net/cache/ba1/91/64/10fcd883cf0d15895d72a638e2ad",
|
||||
"build/prefab/lib/windows/Release_Win32/BallisticaCoreHeadlessInternal.pdb": "https://files.ballistica.net/cache/ba1/1e/69/bf40bc8defe923cfa6d48cb5dd04",
|
||||
"src/ballistica/generated/python_embedded/binding.inc": "https://files.ballistica.net/cache/ba1/7d/3e/229a581cb2454ed856f1d8b564a7",
|
||||
"src/ballistica/generated/python_embedded/bootstrap.inc": "https://files.ballistica.net/cache/ba1/aa/a5/3ddc86d1789b2bf1d376b7671a3d"
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
### 1.7.7 (build 20717, api 7, 2022-08-25)
|
||||
### 1.7.7 (build 20721, api 7, 2022-08-26)
|
||||
- Added `ba.app.meta.load_exported_classes()` for loading classes discovered by the meta subsystem cleanly in a background thread.
|
||||
- Improved logging of missing playlist game types.
|
||||
- Some ba.Lstr functionality can now be used in background threads.
|
||||
|
||||
@ -15,7 +15,7 @@ if TYPE_CHECKING:
|
||||
from typing import Any, Literal
|
||||
import ba
|
||||
|
||||
TA = TypeVar('TA', bound='Actor')
|
||||
ActorT = TypeVar('ActorT', bound='Actor')
|
||||
|
||||
|
||||
class Actor:
|
||||
@ -95,7 +95,7 @@ class Actor:
|
||||
|
||||
return UNHANDLED
|
||||
|
||||
def autoretain(self: TA) -> TA:
|
||||
def autoretain(self: ActorT) -> ActorT:
|
||||
"""Keep this Actor alive without needing to hold a reference to it.
|
||||
|
||||
This keeps the ba.Actor in existence by storing a reference to it
|
||||
|
||||
@ -31,13 +31,11 @@ class Existable(Protocol):
|
||||
"""Whether this object exists."""
|
||||
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
ExistableType = TypeVar('ExistableType', bound=Existable)
|
||||
# pylint: enable=invalid-name
|
||||
ExistableT = TypeVar('ExistableT', bound=Existable)
|
||||
T = TypeVar('T')
|
||||
|
||||
|
||||
def existing(obj: ExistableType | None) -> ExistableType | None:
|
||||
def existing(obj: ExistableT | None) -> ExistableT | None:
|
||||
"""Convert invalid references to None for any ba.Existable object.
|
||||
|
||||
Category: **Gameplay Functions**
|
||||
@ -251,6 +249,10 @@ class _Call:
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
# Some interaction between our ballistica pylint plugin
|
||||
# and this code is crashing starting on pylint 2.15.0.
|
||||
# This seems to fix things for now.
|
||||
# pylint: disable=all
|
||||
WeakCall = Call
|
||||
Call = Call
|
||||
else:
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
namespace ballistica {
|
||||
|
||||
// These are set automatically via script; don't modify them here.
|
||||
const int kAppBuildNumber = 20717;
|
||||
const int kAppBuildNumber = 20721;
|
||||
const char* kAppVersion = "1.7.7";
|
||||
|
||||
// Our standalone globals.
|
||||
|
||||
@ -30,6 +30,8 @@ if TYPE_CHECKING:
|
||||
|
||||
TOOL_NAME = 'bacloud'
|
||||
|
||||
TIMEOUT_SECONDS = 60 * 5
|
||||
|
||||
# Server we talk to (can override via env var).
|
||||
BACLOUD_SERVER_URL = os.getenv('BACLOUD_SERVER_URL', 'https://ballistica.net')
|
||||
|
||||
@ -152,8 +154,11 @@ class App:
|
||||
|
||||
# Using requests module.
|
||||
else:
|
||||
with requests.post(url, headers=headers, data=rdata,
|
||||
files=files) as response_raw:
|
||||
with requests.post(url,
|
||||
headers=headers,
|
||||
data=rdata,
|
||||
files=files,
|
||||
timeout=TIMEOUT_SECONDS) as response_raw:
|
||||
response_raw.raise_for_status()
|
||||
assert isinstance(response_raw.content, bytes)
|
||||
response_content = response_raw.content.decode()
|
||||
|
||||
@ -243,7 +243,7 @@ def push_ipa() -> None:
|
||||
root = Path(sys.argv[0], '../..').resolve()
|
||||
if len(sys.argv) != 3:
|
||||
raise Exception('expected 1 arg (debug or release)')
|
||||
modename = sys.argv[2]
|
||||
modename = sys.argv[2].lower()
|
||||
efrotools.ios.push_ipa(root, modename)
|
||||
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ Supports static typing for message types and possible return types.
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import TYPE_CHECKING, TypeVar
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from efro.error import CleanError, RemoteError, CommunicationError
|
||||
from efro.message._message import EmptyResponse, ErrorResponse
|
||||
@ -18,8 +18,6 @@ if TYPE_CHECKING:
|
||||
from efro.message._message import Message, Response
|
||||
from efro.message._protocol import MessageProtocol
|
||||
|
||||
TM = TypeVar('TM', bound='MessageSender')
|
||||
|
||||
|
||||
class MessageSender:
|
||||
"""Facilitates sending messages to a target and receiving responses.
|
||||
|
||||
@ -27,11 +27,11 @@ if TYPE_CHECKING:
|
||||
from typing import Any, Callable, NoReturn
|
||||
|
||||
T = TypeVar('T')
|
||||
TVAL = TypeVar('TVAL')
|
||||
TARG = TypeVar('TARG')
|
||||
TSELF = TypeVar('TSELF')
|
||||
TRET = TypeVar('TRET')
|
||||
TENUM = TypeVar('TENUM', bound=Enum)
|
||||
ValT = TypeVar('ValT')
|
||||
ArgT = TypeVar('ArgT')
|
||||
SelfT = TypeVar('SelfT')
|
||||
RetT = TypeVar('RetT')
|
||||
EnumT = TypeVar('EnumT', bound=Enum)
|
||||
|
||||
|
||||
class _EmptyObj:
|
||||
@ -44,7 +44,7 @@ else:
|
||||
Call = functools.partial
|
||||
|
||||
|
||||
def enum_by_value(cls: type[TENUM], value: Any) -> TENUM:
|
||||
def enum_by_value(cls: type[EnumT], value: Any) -> EnumT:
|
||||
"""Create an enum from a value.
|
||||
|
||||
This is basically the same as doing 'obj = EnumType(value)' except
|
||||
@ -251,15 +251,15 @@ class DirtyBit:
|
||||
return False
|
||||
|
||||
|
||||
class DispatchMethodWrapper(Generic[TARG, TRET]):
|
||||
class DispatchMethodWrapper(Generic[ArgT, RetT]):
|
||||
"""Type-aware standin for the dispatch func returned by dispatchmethod."""
|
||||
|
||||
def __call__(self, arg: TARG) -> TRET:
|
||||
def __call__(self, arg: ArgT) -> RetT:
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def register(
|
||||
func: Callable[[Any, Any], TRET]) -> Callable[[Any, Any], TRET]:
|
||||
func: Callable[[Any, Any], RetT]) -> Callable[[Any, Any], RetT]:
|
||||
"""Register a new dispatch handler for this dispatch-method."""
|
||||
|
||||
registry: dict[Any, Callable]
|
||||
@ -267,8 +267,8 @@ class DispatchMethodWrapper(Generic[TARG, TRET]):
|
||||
|
||||
# noinspection PyProtectedMember,PyTypeHints
|
||||
def dispatchmethod(
|
||||
func: Callable[[Any, TARG],
|
||||
TRET]) -> DispatchMethodWrapper[TARG, TRET]:
|
||||
func: Callable[[Any, ArgT],
|
||||
RetT]) -> DispatchMethodWrapper[ArgT, RetT]:
|
||||
"""A variation of functools.singledispatch for methods.
|
||||
|
||||
Note: as of Python 3.9 there is now functools.singledispatchmethod,
|
||||
@ -307,7 +307,7 @@ def dispatchmethod(
|
||||
return cast(DispatchMethodWrapper, wrapper)
|
||||
|
||||
|
||||
def valuedispatch(call: Callable[[TVAL], TRET]) -> ValueDispatcher[TVAL, TRET]:
|
||||
def valuedispatch(call: Callable[[ValT], RetT]) -> ValueDispatcher[ValT, RetT]:
|
||||
"""Decorator for functions to allow dispatching based on a value.
|
||||
|
||||
This differs from functools.singledispatch in that it dispatches based
|
||||
@ -318,21 +318,21 @@ def valuedispatch(call: Callable[[TVAL], TRET]) -> ValueDispatcher[TVAL, TRET]:
|
||||
return ValueDispatcher(call)
|
||||
|
||||
|
||||
class ValueDispatcher(Generic[TVAL, TRET]):
|
||||
class ValueDispatcher(Generic[ValT, RetT]):
|
||||
"""Used by the valuedispatch decorator"""
|
||||
|
||||
def __init__(self, call: Callable[[TVAL], TRET]) -> None:
|
||||
def __init__(self, call: Callable[[ValT], RetT]) -> None:
|
||||
self._base_call = call
|
||||
self._handlers: dict[TVAL, Callable[[], TRET]] = {}
|
||||
self._handlers: dict[ValT, Callable[[], RetT]] = {}
|
||||
|
||||
def __call__(self, value: TVAL) -> TRET:
|
||||
def __call__(self, value: ValT) -> RetT:
|
||||
handler = self._handlers.get(value)
|
||||
if handler is not None:
|
||||
return handler()
|
||||
return self._base_call(value)
|
||||
|
||||
def _add_handler(self, value: TVAL,
|
||||
call: Callable[[], TRET]) -> Callable[[], TRET]:
|
||||
def _add_handler(self, value: ValT,
|
||||
call: Callable[[], RetT]) -> Callable[[], RetT]:
|
||||
if value in self._handlers:
|
||||
raise RuntimeError(f'Duplicate handlers added for {value}')
|
||||
self._handlers[value] = call
|
||||
@ -340,42 +340,42 @@ class ValueDispatcher(Generic[TVAL, TRET]):
|
||||
|
||||
def register(
|
||||
self,
|
||||
value: TVAL) -> Callable[[Callable[[], TRET]], Callable[[], TRET]]:
|
||||
value: ValT) -> Callable[[Callable[[], RetT]], Callable[[], RetT]]:
|
||||
"""Add a handler to the dispatcher."""
|
||||
from functools import partial
|
||||
return partial(self._add_handler, value)
|
||||
|
||||
|
||||
def valuedispatch1arg(
|
||||
call: Callable[[TVAL, TARG],
|
||||
TRET]) -> ValueDispatcher1Arg[TVAL, TARG, TRET]:
|
||||
call: Callable[[ValT, ArgT],
|
||||
RetT]) -> ValueDispatcher1Arg[ValT, ArgT, RetT]:
|
||||
"""Like valuedispatch but for functions taking an extra argument."""
|
||||
return ValueDispatcher1Arg(call)
|
||||
|
||||
|
||||
class ValueDispatcher1Arg(Generic[TVAL, TARG, TRET]):
|
||||
class ValueDispatcher1Arg(Generic[ValT, ArgT, RetT]):
|
||||
"""Used by the valuedispatch1arg decorator"""
|
||||
|
||||
def __init__(self, call: Callable[[TVAL, TARG], TRET]) -> None:
|
||||
def __init__(self, call: Callable[[ValT, ArgT], RetT]) -> None:
|
||||
self._base_call = call
|
||||
self._handlers: dict[TVAL, Callable[[TARG], TRET]] = {}
|
||||
self._handlers: dict[ValT, Callable[[ArgT], RetT]] = {}
|
||||
|
||||
def __call__(self, value: TVAL, arg: TARG) -> TRET:
|
||||
def __call__(self, value: ValT, arg: ArgT) -> RetT:
|
||||
handler = self._handlers.get(value)
|
||||
if handler is not None:
|
||||
return handler(arg)
|
||||
return self._base_call(value, arg)
|
||||
|
||||
def _add_handler(self, value: TVAL,
|
||||
call: Callable[[TARG], TRET]) -> Callable[[TARG], TRET]:
|
||||
def _add_handler(self, value: ValT,
|
||||
call: Callable[[ArgT], RetT]) -> Callable[[ArgT], RetT]:
|
||||
if value in self._handlers:
|
||||
raise RuntimeError(f'Duplicate handlers added for {value}')
|
||||
self._handlers[value] = call
|
||||
return call
|
||||
|
||||
def register(
|
||||
self, value: TVAL
|
||||
) -> Callable[[Callable[[TARG], TRET]], Callable[[TARG], TRET]]:
|
||||
self, value: ValT
|
||||
) -> Callable[[Callable[[ArgT], RetT]], Callable[[ArgT], RetT]]:
|
||||
"""Add a handler to the dispatcher."""
|
||||
from functools import partial
|
||||
return partial(self._add_handler, value)
|
||||
@ -383,22 +383,22 @@ class ValueDispatcher1Arg(Generic[TVAL, TARG, TRET]):
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
||||
class ValueDispatcherMethod(Generic[TVAL, TRET]):
|
||||
class ValueDispatcherMethod(Generic[ValT, RetT]):
|
||||
"""Used by the valuedispatchmethod decorator."""
|
||||
|
||||
def __call__(self, value: TVAL) -> TRET:
|
||||
def __call__(self, value: ValT) -> RetT:
|
||||
...
|
||||
|
||||
def register(
|
||||
self, value: TVAL
|
||||
) -> Callable[[Callable[[TSELF], TRET]], Callable[[TSELF], TRET]]:
|
||||
self, value: ValT
|
||||
) -> Callable[[Callable[[SelfT], RetT]], Callable[[SelfT], RetT]]:
|
||||
"""Add a handler to the dispatcher."""
|
||||
...
|
||||
|
||||
|
||||
def valuedispatchmethod(
|
||||
call: Callable[[TSELF, TVAL],
|
||||
TRET]) -> ValueDispatcherMethod[TVAL, TRET]:
|
||||
call: Callable[[SelfT, ValT],
|
||||
RetT]) -> ValueDispatcherMethod[ValT, RetT]:
|
||||
"""Like valuedispatch but works with methods instead of functions."""
|
||||
|
||||
# NOTE: It seems that to wrap a method with a decorator and have self
|
||||
@ -407,18 +407,18 @@ def valuedispatchmethod(
|
||||
# in the function call dict and simply return a call.
|
||||
|
||||
_base_call = call
|
||||
_handlers: dict[TVAL, Callable[[TSELF], TRET]] = {}
|
||||
_handlers: dict[ValT, Callable[[SelfT], RetT]] = {}
|
||||
|
||||
def _add_handler(value: TVAL, addcall: Callable[[TSELF], TRET]) -> None:
|
||||
def _add_handler(value: ValT, addcall: Callable[[SelfT], RetT]) -> None:
|
||||
if value in _handlers:
|
||||
raise RuntimeError(f'Duplicate handlers added for {value}')
|
||||
_handlers[value] = addcall
|
||||
|
||||
def _register(value: TVAL) -> Callable[[Callable[[TSELF], TRET]], None]:
|
||||
def _register(value: ValT) -> Callable[[Callable[[SelfT], RetT]], None]:
|
||||
from functools import partial
|
||||
return partial(_add_handler, value)
|
||||
|
||||
def _call_wrapper(self: TSELF, value: TVAL) -> TRET:
|
||||
def _call_wrapper(self: SelfT, value: ValT) -> RetT:
|
||||
handler = _handlers.get(value)
|
||||
if handler is not None:
|
||||
return handler(self)
|
||||
@ -433,7 +433,7 @@ def valuedispatchmethod(
|
||||
# In reality we just return a raw function call (for reasons listed above).
|
||||
# pylint: disable=undefined-variable, no-else-return
|
||||
if TYPE_CHECKING:
|
||||
return ValueDispatcherMethod[TVAL, TRET]()
|
||||
return ValueDispatcherMethod[ValT, RetT]()
|
||||
else:
|
||||
return _call_wrapper
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user