Type annotate ParameterSet & param()#6726
Conversation
| _S = TypeVar("_S") | ||
|
|
||
|
|
||
| NOTSET = object() |
There was a problem hiding this comment.
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.
Generalized this a bit, otherwise type annotation is very ugly.
There was a problem hiding this comment.
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.
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.
| __all__ = ["Mark", "MarkDecorator", "MarkGenerator", "get_empty_parameterset_mark"] | ||
|
|
||
|
|
||
| def param(*values, **kw): |
There was a problem hiding this comment.
I expanded the kwargs so I can annotate them and so that the types show up in the docs.
Extracted from #6717.