Comments (6)
Did you decorate something with @parametric
by any chance?
from plum.
@PhilipVinc yep, i did
from plum.
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.
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.
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.
Okay, I just noticed that plum
does not support Protocols yet #28 🤦♂️
I will close this.
from plum.
Related Issues (20)
- Comparison documentation on default values. HOT 2
- typing_extensions.Annotated not supported HOT 4
- Replace `inspect.signature` with `beartype._util.func.arg.utilfuncargiter.iter_func_args` HOT 3
- More issues with Annotated HOT 11
- Truncating dispatch error message (types, instead of instances) HOT 4
- Multiple functions arguements to be friendly with MyPy HOT 3
- Precedence issue introduced by redefinition of method in inheritor class HOT 13
- `Iterable[T]` not being dispatched HOT 7
- Issue on page /keyword_arguments.html HOT 4
- `multimeta`-like metaclass for plum HOT 12
- Support decorator syntax for `add_conversion_method` HOT 1
- `AmbiguousLookupError` with parametrized dispatching in pytest HOT 3
- `TypeError: Test.__call__() got an unexpected keyword argument 'a'` HOT 16
- Option to ignore errors when resolving pending registrations while accessing `methods` attribute HOT 4
- Set precedence of individual types HOT 6
- `process` function getting the arguments for `Bundle`'s `__new__` method? HOT 4
- Enable RTD builds for PRs HOT 2
- Use `codspeed` for benchmarks HOT 8
- Configure mypy for CI HOT 3
- `Union[type[...], ...]` and `type` not the same as `type[...]`, `...`, and `type` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plum.