Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Type Dict cannot be instantiated" error when executing code line from readme #34

Closed
jn73 opened this issue Aug 26, 2019 · 7 comments
Closed

Comments

@jn73
Copy link

jn73 commented Aug 26, 2019

I get this error when i try to match a Dict[str, int] :

I cant find any imports for Dict but assumed it was from typing?

In [1]: from pampy import match, _

In [2]: from typing import Dict

In [3]: match({"a": 1, "b": 2}, Dict[str, int], lambda x: x)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-e5c0ae675d5a> in <module>
----> 1 match({"a": 1, "b": 2}, Dict[str, int], lambda x: x)

~/.virtualenvs/sqlparse/lib/python3.7/site-packages/pampy/pampy.py in match(var, default, strict, *args)
    176
    177     for patt, action in pairs:
--> 178         matched_as_value, args = match_value(patt, var)
    179
    180         if matched_as_value:

~/.virtualenvs/sqlparse/lib/python3.7/site-packages/pampy/pampy.py in match_value(pattern, value)
     45         return match_dict(pattern, value)
     46     elif callable(pattern):
---> 47         return_value = pattern(value)
     48         if return_value is True:
     49             return True, [value]

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/typing.py in __call__(self, *args, **kwargs)
    666     def __call__(self, *args, **kwargs):
    667         if not self._inst:
--> 668             raise TypeError(f"Type {self._name} cannot be instantiated; "
    669                             f"use {self._name.lower()}() instead")
    670         result = self.__origin__(*args, **kwargs)

TypeError: Type Dict cannot be instantiated; use dict() instead
@jn73
Copy link
Author

jn73 commented Aug 30, 2019

same with:

match(1, Union[int, str], lambda s: s)

=> TypeError: Cannot instantiate typing.Union

@jn73
Copy link
Author

jn73 commented Aug 30, 2019

version: Python 3.7.3

@jn73
Copy link
Author

jn73 commented Aug 30, 2019

Looks like there's some issue with the version (0.2.1) i have installed (pip install pampy).

When i did a 'pip install -e .' from the latest source it works.

@miaoever
Copy link

miaoever commented Sep 2, 2019

Same issue here for the Python 3.7.3, installed by: pip install pampy

@aambrozkiewicz
Copy link

+1 same here

@santinic
Copy link
Owner

santinic commented Sep 13, 2019

Sorry, typings are not supported yet in the pip version. Release 3.0.0 will have it, but I won't have time for a few weeks.
You can pip install the latest commit, and that should work. Try something like:

pip install git+git://github.com/santinic/pampy.git@27de362e63310eaa5044c7c87414d19aacefef56

@santinic
Copy link
Owner

santinic commented Nov 7, 2019

Just published v0.3

@santinic santinic closed this as completed Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants