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

Minor fixes and updates in trait_types.pyi; new ctraits.pyi #1661

Merged
merged 7 commits into from
Aug 4, 2022

Conversation

mdickinson
Copy link
Member

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.

Copy link
Contributor

@rahulporuri rahulporuri left a comment

Choose a reason for hiding this comment

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

LGTM.

Comment on lines +61 to +63
factory: _CallableType[..., _Any] = ...,
args: _Tuple[_Any, ...] = ...,
kw: _DictType[str, _Any] = ...,
Copy link
Contributor

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).

Copy link
Member Author

@mdickinson mdickinson Aug 4, 2022

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.

Copy link
Contributor

@corranwebster corranwebster left a 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.

@mdickinson mdickinson merged commit 9f5fe4d into main Aug 4, 2022
@mdickinson mdickinson deleted the stubs-cleanup branch August 4, 2022 10:38
mdickinson added a commit that referenced this pull request Aug 9, 2022
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)
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.

3 participants