-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Conversation
|
||
|
||
_T = TypeVar("_T") | ||
_S = TypeVar("_S") | ||
|
||
|
||
NOTSET = object() |
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.
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)) |
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.
Generalized this a bit, otherwise type annotation is very ugly.
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.
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.
8e90a10
to
4bfcf62
Compare
if isinstance(marks, MarkDecorator): | ||
marks = (marks,) | ||
else: | ||
assert isinstance(marks, (tuple, list, set)) |
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.
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): |
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 expanded the kwargs so I can annotate them and so that the types show up in the docs.
Extracted from #6717.