Skip to content

Type annotate ParameterSet & param() #6726

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

Closed
wants to merge 1 commit into from

Conversation

bluetech
Copy link
Member

Extracted from #6717.



_T = TypeVar("_T")
_S = TypeVar("_S")


NOTSET = object()
Copy link
Member Author

Choose a reason for hiding this comment

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

object() doesn't produce a singleton on the type level, so I had to switch it to an idiom that does.

if isinstance(marks, MarkDecorator):
marks = (marks,)
else:
assert isinstance(marks, (tuple, list, set))
Copy link
Member Author

Choose a reason for hiding this comment

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

Generalized this a bit, otherwise type annotation is very ugly.

Copy link
Member Author

Choose a reason for hiding this comment

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

But turns out py3.5 doesn't have collections.abc.Collection, so I changed the runtime check to collections.abc.Sequence | set, but left the type as Collection. So there will be a slight mismatch until we can drop py3.5.

@bluetech bluetech force-pushed the parameterset-annotate branch from 8e90a10 to 4bfcf62 Compare February 13, 2020 17:04
@bluetech bluetech changed the title Type annotate ParameterSet Type annotate ParameterSet & param() Feb 13, 2020
if isinstance(marks, MarkDecorator):
marks = (marks,)
else:
assert isinstance(marks, (tuple, list, set))
Copy link
Member Author

Choose a reason for hiding this comment

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

But turns out py3.5 doesn't have collections.abc.Collection, so I changed the runtime check to collections.abc.Sequence | set, but left the type as Collection. So there will be a slight mismatch until we can drop py3.5.

@@ -14,7 +18,11 @@
__all__ = ["Mark", "MarkDecorator", "MarkGenerator", "get_empty_parameterset_mark"]


def param(*values, **kw):
Copy link
Member Author

Choose a reason for hiding this comment

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

I expanded the kwargs so I can annotate them and so that the types show up in the docs.

@bluetech bluetech closed this Feb 28, 2020
@bluetech bluetech deleted the parameterset-annotate branch February 28, 2020 12:08
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.

1 participant