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

Extended support from typing.List to typing.Iterable, and from typing.Dict to typing.Mapping #64

Closed
wants to merge 1 commit into from

Conversation

smarie
Copy link

@smarie smarie commented Jan 30, 2018

Fixes #52, Fixes #51, fixes #47.

You might wish to include the following basic tests:

from enforce import runtime_validation, config
from enforce.exceptions import RuntimeTypeError
config(dict(mode='covariant'))  # by the way, so sad that this is not the default :)


########## SEQUENCE / ITERABLE / SET / GENERATOR
from typing import Sequence, Iterable, Set, Generator

@runtime_validation
def seq(s: Sequence[str]):
    pass

@runtime_validation
def it(s: Iterable[str]):
    pass


seq(['a'])
# transform this into appropriate test handler
try:
    seq(['r', 1])
    raise Exception('failed!')
except RuntimeTypeError:
    pass

it(['a'])
# transform this into appropriate test handler
try:
    it(['r', 1])
    raise Exception('failed!')
except RuntimeTypeError:
    pass


@runtime_validation
def st(m: Set[int]):
    pass


st({2, 2})
# transform this into appropriate test handler
try:
    st({'r', 1})
    raise Exception('failed!')
except RuntimeTypeError:
    pass


@runtime_validation
def generator() -> Generator[int, None, None]:
    i = 0
    while True:
        if i == 0:
            yield i
        else:
            yield 'a string! it cannot be detected by enforce but thats a bit normal'
        i += 1


g = generator()
print(next(g))
print(next(g))


########## MAPPING
from typing import Mapping


@runtime_validation
def bar(m: Mapping[int, int]):
    pass


bar({2: 2})
# transform this into appropriate test handler
try:
    bar({'r': 1})
    raise Exception('failed!')
except RuntimeTypeError:
    pass

@coveralls
Copy link

coveralls commented Jan 30, 2018

Coverage Status

Coverage decreased (-0.04%) to 93.628% when pulling e0defb4 on smarie:generics-fix into caf1dc3 on RussBaz:master.

@RussBaz
Copy link
Owner

RussBaz commented Jan 30, 2018

Wow, thanks! However, I must say that you are trying to push your PRs into the 'master' branch. The development is actually done in the 'dev' branch, I have been pushing updates into it since the last release. Please check it with the a 'dev' branch first. There were few important changes. Thank you again for taking your time to help!

@smarie
Copy link
Author

smarie commented Jan 31, 2018

Ok I'll try to find a way to create a single pull request from dev branch, containing both fixes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants