Skip to content

Commit 49100f3

Browse files
committed
Add MMCorePlusProxy overloads
Makes the original MMCorePlusProxy syntax work
1 parent bfb4b32 commit 49100f3

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

examples/remote_mda.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import numpy as np
22
from useq import MDAEvent, MDASequence, TIntervalLoops
33

4-
from pymmcore_remote import MMCorePlusProxy, server, server_process
4+
from pymmcore_remote import MMCorePlusProxy, server_process
55

66
PORT = 55999
77

88
# this context manager ensures a server is running, or creates a new one if not.
99
with server_process(port=PORT):
10-
uri = f"PYRO:{server.CORE_NAME}@{server.DEFAULT_HOST}:{PORT}"
1110
# create a proxy object that communicates with the MMCore object on the server
12-
with MMCorePlusProxy(uri=uri) as core:
11+
with MMCorePlusProxy(port=PORT) as core:
1312
# continue using core as usual:
1413
core.loadSystemConfiguration()
1514

src/pymmcore_remote/client.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import threading
4-
from typing import TYPE_CHECKING, Any, ClassVar, cast
4+
from typing import TYPE_CHECKING, Any, ClassVar, cast, overload
55

66
import Pyro5.api
77
import Pyro5.errors
@@ -46,11 +46,37 @@ def instance(cls, uri: Pyro5.api.URI | str) -> MMCorePlusProxy:
4646
cls._instances[str(uri)] = cls(uri)
4747
return cls._instances[str(uri)]
4848

49+
@overload
4950
def __init__(
50-
self, uri: Pyro5.api.URI | str | None = None, connected_socket: Any = None
51+
self,
52+
*,
53+
port: int,
54+
object_id: str | None = None,
55+
host: str | None = None,
56+
connected_socket: Any = None,
57+
) -> None: ...
58+
@overload
59+
def __init__(
60+
self,
61+
uri: Pyro5.api.URI | str,
62+
*,
63+
connected_socket: Any = None,
64+
) -> None: ...
65+
66+
def __init__(
67+
self,
68+
uri: Pyro5.api.URI | str | None = None,
69+
*,
70+
object_id: str | None = None,
71+
host: str | None = None,
72+
port: int | None = None,
73+
connected_socket: Any = None,
5174
) -> None:
5275
if uri is None:
53-
uri = f"PYRO:{server.CORE_NAME}@{server.DEFAULT_HOST}:{server.DEFAULT_PORT}"
76+
object_id = server.CORE_NAME if object_id is None else object_id
77+
host = server.DEFAULT_HOST if host is None else host
78+
port = server.DEFAULT_PORT if port is None else port
79+
uri = f"PYRO:{object_id}@{host}:{port}"
5480
register_serializers()
5581
super().__init__(uri, connected_socket=connected_socket)
5682
self._instances[str(self._pyroUri)] = self

0 commit comments

Comments
 (0)