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

Use stub files *.pyi rather than @with_signature everywhere possible #50

Open
smarie opened this issue Oct 7, 2019 · 7 comments
Open

Comments

@smarie
Copy link
Owner

smarie commented Oct 7, 2019

That will be more compliant with IDE autocomplete features.

@galen1090
Copy link

I'm writing a library fully typed with annotations and checked with mypy. I want to use python-valid8 to validate my functions but right now I can't without make all of them untyped (and it's the opposite of what I want).
The main problem are the decorators, for other public functions I can make stub files.
There are plans to made it compliant to mypy?

Thanks

@smarie
Copy link
Owner Author

smarie commented Jan 16, 2020

Unfortunately I have never used mypy, so I do not have the experience for this. I would gladly accept any PR but please explain first what you intend to do (for example with a single mod) before going into too much development.

I would be curious to understand why mypy raises an issue here: after all it is scanning your code, not mine ? :)

@galen1090
Copy link

Here a simple example:

from mini_lambda import s, Len
from valid8 import validate_arg
from valid8.validation_lib import instance_of

@validate_arg('name', instance_of(str), Len(s) > 0, 
              help_msg='name should be a non-empty string')
def build_house(name: str) -> int:
    print(f'name is: {name}')
    return 10

def build_house2(name: str) -> int:
    print(f'name is: {name}')
    return 10

build_house("john")
build_house(5)

build_house2("john")
build_house2(5)

this is the output of mypy:

test.py:1: error: Cannot find implementation or library stub for module named 'mini_lambda'
test.py:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
test.py:2: error: Cannot find implementation or library stub for module named 'valid8'
test.py:3: error: Cannot find implementation or library stub for module named 'valid8.validation_lib'
test.py:5: error: Untyped decorator makes function "build_house" untyped
test.py:19: error: Argument 1 to "build_house2" has incompatible type "int"; expected "str"

As you can see, I pass a wrong type to either build_house and build_house2 function, but as mypy said, validate_arg untyped decorator makes function build_house untyped.
So all function decorated with valid8 decorator become untyped and cannot be checked.

smarie pushed a commit that referenced this issue Jan 17, 2020
@smarie
Copy link
Owner Author

smarie commented Jan 17, 2020

I see, thanks for the details! I pushed a PR for this: #54

The PR is only focused on the module you mention for now. Can you try and see if it solves your problem ? Thanks !

@galen1090
Copy link

Sorry for the delay.
I have tried it and everything is like before.

@smarie
Copy link
Owner Author

smarie commented Jan 22, 2020

Thanks for the feedback ! I managed to reproduce this and fix it.
It was actually not related to the stub file presence but to the type hint of the decorator function, that was simply wrong. I opened a dedicated issue #56

smarie added a commit that referenced this issue Jan 22, 2020
On the way to fixing #50 : created stubs for module `entry_points_annotations`
@smarie
Copy link
Owner Author

smarie commented Jan 22, 2020

This is all in 5.1.0 that should ship in a few minutes when travis has done processing. Let me know how it goes ! Thanks again for the feedback

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

No branches or pull requests

2 participants