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

Set[] return type has errors #33

Closed
wizzardx opened this issue Jan 26, 2017 · 2 comments
Closed

Set[] return type has errors #33

wizzardx opened this issue Jan 26, 2017 · 2 comments

Comments

@wizzardx
Copy link

wizzardx commented Jan 26, 2017

Working with 0.3.1, installed from PyPI

Example code:

import enforce

from typing import Set

@enforce.runtime_validation
def test() -> Set[int]:
    return set([1,2,3])

test()

Error:

Traceback (most recent call last):
  File "/tmp/x/py35/venv/lib/python3.5/site-packages/enforce/nodes.py", line 403, in preprocess_data
    enforcer = data.__enforcer__
AttributeError: 'list' object has no attribute '__enforcer__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 9, in 
    test()
  File "/tmp/x/py35/venv/lib/python3.5/site-packages/enforce/decorators.py", line 123, in universal
    return enforcer.validate_outputs(result)
  File "/tmp/x/py35/venv/lib/python3.5/site-packages/enforce/enforcers.py", line 95, in validate_outputs
    if not self.validator.validate(output_data, 'return'):
  File "/tmp/x/py35/venv/lib/python3.5/site-packages/enforce/validator.py", line 26, in validate
    result = visit(validation_tree)
  File "/tmp/x/py35/venv/lib/python3.5/site-packages/enforce/utils.py", line 17, in visit
    stack.append(last.send(last_result))
  File "/tmp/x/py35/venv/lib/python3.5/site-packages/enforce/nodes.py", line 45, in validate
    clean_data = self.preprocess_data(validator, data)
  File "/tmp/x/py35/venv/lib/python3.5/site-packages/enforce/nodes.py", line 405, in preprocess_data
    return GenericProxy(data)
  File "/tmp/x/py35/venv/lib/python3.5/site-packages/enforce/enforcers.py", line 129, in __init__
    raise TypeError('Only generics can be wrapped in GenericProxy')
TypeError: Only generics can be wrapped in GenericProxy

If we change Set to List then it works fine though:

import enforce

from typing import List

@enforce.runtime_validation
def test() -> List[int]:
    return [1,2,3]

test()
@hwayne
Copy link
Contributor

hwayne commented Jan 27, 2017 via email

@RussBaz
Copy link
Owner

RussBaz commented Jan 28, 2017

It is now fixed in the dev branch. Thanks for the reporting.

@RussBaz RussBaz closed this as completed Jan 28, 2017
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

3 participants