Skip to content

Conversation

@gpauloski
Copy link
Collaborator

Description

The changes are based on https://www.youtube.com/watch?v=tH3Nul6jDQM which uses find_member rather than analyze_member_access and ctx.api.fail to raise custom error messages.

Previously, attribute lookup errors on a Proxy[Foo] would raise an error that did not make it clear the type was a Proxy: "Foo" has no attribute "y". Now the error will now look like: "OwnedProxy[Foo]" has no attribute "y".

Error on Union types have also been improved. For example: Item "Proxy[Foo]" of "Proxy[Foo] | Bar" has no attribute "y".

Fixes N/A

Type of Change

  • Breaking Change (fix or enhancement which changes existing semantics of the public interface)
  • Enhancement (new features or improvements to existing functionality)
  • Bug (fixes for a bug or issue)
  • Internal (refactoring, style changes, testing, optimizations)
  • Documentation update (changes to documentation or examples)
  • Package (dependencies, versions, package metadata)
  • Development (CI workflows, pre-commit, linters, templates)
  • Security (security related changes)

Testing

Added more unit tests, and validated with the following script.

from dask.distributed import Client
from proxystore.connectors.file import FileConnector
from proxystore.store import Store
from proxystore.proxy import Proxy
from proxystore.store.ref import OwnedProxy

class Foo:
    x: str = 'hello'

    def bar(self) -> int:
        return 42

class Bar:
    y: str = 'hello'


def main() -> None:
    with Store(
        name='dask',
        connector=FileConnector('/tmp/proxystore-cache'),
        populate_target=True,
        register=True,
    ) as store:
        # proxy: Proxy[Foo] | Foo = store.proxy(Foo())
        proxy: Proxy[Foo] = store.proxy(Foo())
        reveal_type(proxy.x)

        # owned_proxy: OwnedProxy[Foo] | Foo = store.owned_proxy(Foo())
        owned_proxy: OwnedProxy[Foo] = store.owned_proxy(Foo())
        reveal_type(owned_proxy.x)

        reveal_type(owned_proxy.bar())

        reveal_type(owned_proxy.y)

        p: Proxy[Foo] | Bar = store.proxy(Foo())
        reveal_type(p.y)


if __name__ == '__main__':
    main()

Pull Request Checklist

Please confirm the PR meets the following requirements.

  • Tags added to PR (e.g., breaking, bug, enhancement, internal, documentation, package, development, security).
  • Code changes pass pre-commit (e.g., mypy, ruff, etc.).
  • Tests have been added to show the fix is effective or that the new feature works.
  • New and existing unit tests pass locally with the changes.
  • Docs have been updated and reviewed if relevant.

@gpauloski gpauloski added the enhancement New features or improvements to existing functionality label Jun 26, 2024
The changes are based on https://www.youtube.com/watch?v=tH3Nul6jDQM
which uses find_member rather than analyze_member_access and
ctx.api.fail to raise custom error messages.

Previously, attribute lookup errors on a Proxy[Foo] would raise an error
that did not make it clear the type was a Proxy:
  "Foo" has no attribute "y"
Now the error will now look like:
  "OwnedProxy[Foo]" has no attribute "y"

Error on Union types have also been improved. For example:
  Item "Proxy[Foo]" of "Proxy[Foo] | Bar" has no attribute "y"
@gpauloski gpauloski merged commit b7ad55a into main Jun 26, 2024
@gpauloski gpauloski deleted the mypy-plugin branch June 26, 2024 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New features or improvements to existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants