Skip to content

proxystore.mypy_plugin

ProxyStore mypy plugin.

The Proxy class behaves poorly with mypy out of the box. Consider the following example. Mypy can determine that proxy is of type Proxy[Foo] but is unable to determine the correct types when accessing an attribute of Foo indirectly via the Proxy instance.

from proxystore.proxy import Proxy

class Foo:
    def bar(self) -> int:
        return 42

def factory() -> Foo:
    return Foo()

proxy = Proxy(factory)
reveal_type(proxy)  # Revealed type is "Proxy[Foo]"

bar = proxy.bar()
reveal_type(bar)  # Revealed type is "Any"

ProxyStore (v0.6.5 and later) comes with an optional mypy plugin which can fix these type resolution limitations. With the mypy plugin enabled, we get the correct type.

1
2
3
4
5
proxy = Proxy(factory)
reveal_type(proxy)  # Revealed type is "Proxy[Foo]"

bar = proxy.bar()
reveal_type(bar)  # Revealed type is "int"

Enable the plugin by adding proxystore.mypy_plugin to the list of plugins in your mypy config file.

  • pyproject.toml
    [tools.mypy]
    plugins = ["proxystore.mypy_plugin"]
    
  • mypy.ini and setup.cfg
    [mypy]
    plugins = proxystore.mypy_plugin