-
Notifications
You must be signed in to change notification settings - Fork 218
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
add typing information #475
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea, but can't we just add the annotations to voluptuous directly? I'm okay with dropping support for older Pythons that don't support it.
That's also fine. I didn't want to drop support just yet, but with your approval I'll merge them into the source :) |
|
||
Enum: typing.Union[type, None] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, huh, I've never seen this syntax before, TIL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually you won't have to do this because the type can be inferred from context, but here it assumed it's always a type
due to the import and then complains about the = None
in the except ModuleError
, so you'll have to be a bit more explicit :)
I'm not quite sure why CI is failing:
|
seems like nobody reported the issue ;)
|
@alecthomas Could you perhaps approve running the workflows to check whether that was indeed the fix? |
Approved, but unfortunately there are still failures |
Ah, I think the |
Getting there step-by-step :) . 2.7 is not yet happy and neither is flake8. 3.6 does not seem to exist as Github actions (anymore)? |
Feel free to drop 2.7 if you like. |
Judging by the content of available python versions, it's still there, but only if you're running the job on ubuntu 20.04. However, as stated in the job log, ubuntu 22.04 is used. So either python 3.6 would need to be not tested anymore, or As Python 3.6 reached End Of Life at the end of 2021 (after 5 years from release, more than 1 year ago), I would like to suggest to the Voluptuous maintainers to consider dropping active support for it. |
Definitely works for me! |
Should be another step closer :) |
🤞 |
Success! |
Lovely, thank you! |
@@ -1148,7 +1159,7 @@ class Required(Marker): | |||
{'key': []} | |||
""" | |||
|
|||
def __init__(self, schema, msg=None, default=UNDEFINED, description=None): | |||
def __init__(self, schema: dict, msg: typing.Optional[str] = None, default=UNDEFINED, description: typing.Optional[str] = None) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct? Required
can also take other scalar types e.g. the example in its docstring: schema = Schema({Required('key'): str})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I don't think it is. Want to send a PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I've overlooked that one. Commit coming up
@@ -7,6 +9,9 @@ | |||
|
|||
import itertools | |||
from voluptuous import error as er | |||
from collections.abc import Generator | |||
import typing | |||
from voluptuous.error import Error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error
could have been used as er.Error
and this import would be not needed
add typing stubs to help IDE's and type checkers such as
mypy
andpyright
This deprecates the outdated https://github.com/ryanwang520/voluptuous-stubs