-
Notifications
You must be signed in to change notification settings - Fork 85
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
Minor fixes and updates in trait_types.pyi; new ctraits.pyi #1661
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.
LGTM.
factory: _CallableType[..., _Any] = ..., | ||
args: _Tuple[_Any, ...] = ..., | ||
kw: _DictType[str, _Any] = ..., |
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.
This would seem like a use-case for ParamSpec
(but that would imply using typing-extensions
for now).
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'm not seeing how to use ParamSpec
here; any suggestions?
What I'd like to do is something like:
P = ParamSpec("P")
class Any(_TraitType[_Any, _Any]):
def __init__(
self,
default_value: _Any = ...,
*,
factory: _CallableType[P, _Any] = ...,
args: P.args = ...,
kw: P.kwargs = ...,
**metadata: _Any,
) -> None:
...
But it looks as though P.args
and P.kwargs
can't be used this way - they can only be used in the context of *args
and **kwargs
.
We already have the dependence on typing-extensions
, so I'm not averse to expanding that dependence.
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.
LGTM, modulo I think there is an Any
where we want _Any
.
Co-authored-by: Corran Webster <cwebster@enthought.com>
This PR makes some minor type-stub related fixes and cleanups, as part of an incremental effort to get the stubs into a usable state. * Add suitable flake8 exclusions for type stubs (it's common to put the ... on the same line as a function def, for example; black does that, but flake8 complains about it). * Add new ctraits.pyi type stubs. It's not complete, but it's sufficient to stop complaints in some other parts of the codebase. * Fix confusion with int being both the built-in type and an enum name in ValidateTrait * Several fixes in trait_types.pyi. In particular, Pylance/Pyright doesn't like missing type variables, even though the typing documentation says that it should be okay to use e.g., plain Callable instead of Callable[..., Any]. * Fix some non-standard double indentation in the trait_types.pyi stubs. Co-authored-by: Corran Webster <cwebster@enthought.com> (cherry picked from commit 9f5fe4d)
This PR makes some minor type-stub related fixes and cleanups, as part of an incremental effort to get the stubs into a usable state.
...
on the same line as a functiondef
, for example; black does that, but flake8 complains about it).ctraits.pyi
type stubs. It's not complete, but it's sufficient to stop complaints in some other parts of the codebase.int
being both the built-in type and an enum name inValidateTrait
trait_types.pyi
. In particular, Pylance/Pyright doesn't like missing type variables, even though thetyping
documentation says that it should be okay to use e.g., plainCallable
instead ofCallable[..., Any]
.trait_types.pyi
stubs.