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

Various doc updates #3314

Merged
merged 6 commits into from
May 3, 2017
Merged

Various doc updates #3314

merged 6 commits into from
May 3, 2017

Conversation

gvanrossum
Copy link
Member

No description provided.

@gvanrossum
Copy link
Member Author

@sixolet Can you review the docs I wrote for flexible callable here?

Copy link
Collaborator

@sixolet sixolet left a comment

Choose a reason for hiding this comment

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

A couple wording nits and one factual quibble.


As an experimental mypy extension, you can specify ``Callable`` types
that support keyword arguments, optional arguments, and more. The
"argument" part of the ``Callable`` specification (the part specifying
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where you specify the arguments of a Callable, you can choose to supply just the type of a nameless positional argument, or an "argument specifier" representing a more complicated form of argument.

**kwargs: int) -> int:
...

F = Callable[[Arg(int), # No argument name given
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider making this just int, to show that a raw type has no arg name and that you can mix them?


MyFunc = Callable[[Arg(int), Arg(str), Arg(int)], float]

A ``Callable`` with unspecified argument types, such as
Copy link
Collaborator

Choose a reason for hiding this comment

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

This equivalency is near, but not entirely true. A Callable[..., int] gets is_ellipsis_args set to True, unlike Callable[[VarArg(), KwArg()], int]. A Callable with ellipsis args is not only considered a subtype of all Callables with compatible return types (which it naturally is), but also a supertype of all Callables with compatible return types (which is weird and special). This is the only other wart in the type system I know of that's comparable to Any.

.. note::

This feature is experimental. Details of the implementation may
change and there may be unknown limitations. **IMPORTANT:** At
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove the first "at runtime" and maybe make it "Each of the functions above currently returns its type argument..."

(to remove the awkwardly repeated phrase)

Arg(int, 'b'),
DefaultArg(int, 'c'),
VarArg(int),
NamedArg(int, 'd'),
Copy link
Member

Choose a reason for hiding this comment

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

This is probably the wrong place for this discussion, but why don't we call this KeywordOnlyArg? NamedArg is confusing because normal args are also named.

Copy link
Member Author

Choose a reason for hiding this comment

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

That discussion can go in python/typing#264, which itself has a few naming differences from Naomi's PRs (#2426 and python/typeshed#684). Or it can go into Naomi's PEP once she's written it.

@@ -16,6 +16,7 @@ now have type annotations using either of the two forms:

.. code-block:: python

from typing import Optionsl
Copy link
Member

Choose a reason for hiding this comment

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

Optional

@gvanrossum
Copy link
Member Author

Addressed the review comments. I decided not to explain in detail the difference between Callable[..., T] and the other form -- it's esoteric and hard to explain and nobody outside mypy dev circles cares.


MyOtherFunc = Callable[..., int]

is (roughly) equivalent to
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like "roughly" here 😈

Copy link
Collaborator

@sixolet sixolet left a comment

Choose a reason for hiding this comment

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

Ok LGTM now.

@gvanrossum gvanrossum merged commit dfb94c1 into master May 3, 2017
@gvanrossum gvanrossum deleted the docs-update branch May 3, 2017 23:37
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