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

Add support for Optional[Tuple[...]] (#115) #116

Merged
merged 2 commits into from
Jun 21, 2022

Conversation

neelmraman
Copy link
Contributor

Closes #115

lib/defopt.py Outdated
@@ -699,7 +703,7 @@ def _get_type_from_doc(name, globalns):
# Support for sphinx-specific "list[type]", "tuple[type]" syntax; only
# needed for Py<3.9.
# (This intentionally won't catch `List` or `typing.List`.)
match = re.match(r'(list|tuple)\[([\w\.]+)\]', name)
match = re.match(r'(list|tuple)\[([\w\.,]+)\]', name)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comma is specifically for the case where you have a multiple-item tuple + union operator typed in a docstring rather than a type hint

lib/defopt.py Outdated
raise ValueError(
"Optional tuples of length greater than one are not "
"supported with use of a NoneType parser due to ambiguity."
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we should also disable support for 1-element tuples for now, per #115 (comment)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@anntzer
Copy link
Owner

anntzer commented Jun 18, 2022

Mostly looks good (in light of #115 (comment)), just one comment.

@anntzer
Copy link
Owner

anntzer commented Jun 21, 2022

I allowed myself to push various small tweaks directly to your branch; will squash-merged once tests pass and if you agree with the changes I made.

test_defopt.py Outdated
def _parse_none(i):
if i.lower() == 'none':
return None
else:
raise ValueError('{} is not a valid None string'.format(i))
with self.assertRaises(ValueError):
self.assertEqual(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah whoops the self.assertEqual was a typo from copy/pasting. Thanks for catching.

@neelmraman
Copy link
Contributor Author

Yup the changes look good. Most of the formatting differences seem to be from me running my changes through black, but happy to defer to whatever autoformatting tool/style convention you're using instead.

@anntzer anntzer merged commit f68a70b into anntzer:main Jun 21, 2022
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

Successfully merging this pull request may close these issues.

Should Optional[Tuple[type1]] be supported
2 participants