Giter VIP home page Giter VIP logo

Comments (6)

PhilipVinc avatar PhilipVinc commented on August 21, 2024

Did you decorate something with @parametric by any chance?

from plum.

mofeing avatar mofeing commented on August 21, 2024

@PhilipVinc yep, i did

from plum.

mofeing avatar mofeing commented on August 21, 2024

Okay, I solved it by renaming the constructors to __init and making the __init__ call the dispatched method.

class BlockArray:
    def __init__(self, *args, **kwargs):
        self.__init(*args, **kwargs)
    ...

Maybe a note in the readme would useful.

from plum.

PhilipVinc avatar PhilipVinc commented on August 21, 2024

Can you send me a MWE that fails? i'll try to fix this.
(I'm unsure what is failing).

parametric classes get their __new__ method overridden, and it calls __infer_type_parameter__ when constructed.
For some reason dispatch fails on __infer_type_parameter__ but without a full MWE i don't know what's going wrong.

from plum.

mofeing avatar mofeing commented on August 21, 2024

I've been trying to replicate the error but it looks like the __init__ was not the error. Now it seems it breaks on the lookup of a Protocol as a parameter.

from typing import List, Tuple, Protocol, runtime_checkable
from plum import dispatch, parametric
import numpy as np

@runtime_checkable
class Array(Protocol):
    def __array__(self) -> np.ndarray:
        pass


@parametric
class A:
    @dispatch
    def __init__(self, a: List[int]):
        print("list")

    @dispatch
    def __init__(self, a: Tuple[int]):
        print("tuple")

    @dispatch
    def __init__(self: List[Array]):
        print("list of array")

    @classmethod
    def __infer_type_parameter__(cls, *args, **kwargs):
        return object

# ok
assert issubclass(np.ndarray, Array)

# ok
A((1,))

# ok
A([1])

# NotFoundLookupError
A([np.zeros(1)])

Error log:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "plum/function.py", line 587, in plum.function._BoundFunction.__call__
  File "plum/function.py", line 536, in plum.function.Function.__call__
  File "plum/function.py", line 493, in plum.function.Function.resolve_method
  File "plum/function.py", line 464, in plum.function.Function.resolve_method
  File "plum/function.py", line 435, in plum.function.Function.resolve_signature
plum.function.NotFoundLookupError: For function "__init__" of __main__.A, signature Signature(__main__.A, List[numpy.ndarray]) could not be resolved.

should i open a new issue or change the title of this?

from plum.

mofeing avatar mofeing commented on August 21, 2024

Okay, I just noticed that plum does not support Protocols yet #28 🤦‍♂️

I will close this.

from plum.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.