Skip to content

More documentation updates #5053

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

Merged
merged 5 commits into from
May 31, 2018
Merged

More documentation updates #5053

merged 5 commits into from
May 31, 2018

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented May 15, 2018

Partial list of changes:

  • Move a bunch of less core functionality to later in the documentation to
    make it easier to get started with mypy.

  • Remove some obsolete things.

  • Migrate more examples to use variable annotations.

  • Clarify various explanations.

Partial list of changes:

* Move a bunch of less core functionality to later in the documentation to
  make it easier to get started with mypy.

* Remove some obsolete things.

* Migrate more examples to use variable annotations.

* Clarify various explanations.
first overloaded definition, and ignores the type annotations on the
implementation of ``__getitem__``. The code in the body of the
definition of ``__getitem__`` is checked against the annotations on
the the corresponding declaration. In this case the body is checked
Copy link
Member

Choose a reason for hiding this comment

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

"the" is duplicated


The annotations on the function body must be compatible with the
types given for the overloaded variants listed above it. The type
checker will verify that all the types listed the overloaded variants
Copy link
Member

Choose a reason for hiding this comment

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

missing a preposition between "listed" and "the" (probably "for")

case it checks that the parameter type ``int`` and the return type
``T`` are compatible with ``Union[int, slice]`` and
``Union[T, Sequence[T]]`` for the first variant. For the second
variant it verifies that the parameter type ``slice`` are the return
Copy link
Member

Choose a reason for hiding this comment

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

are -> and

***********************

As an experimental mypy extension, you can specify ``Callable`` types
that support keyword arguments, optional arguments, and more. Where
Copy link
Member

Choose a reason for hiding this comment

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

Where -> When

.. code-block:: python

class A:
x = None # type: List[int] # Declare attribute 'x' of type List[int]
Copy link
Member

Choose a reason for hiding this comment

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

Should we mention the special case where this allows None even if strict optional is on?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea, added a short discussion of the special case.

def __iter__(self) -> Iterator[T]

``Iterator[T]``
---------------
Copy link
Member

Choose a reason for hiding this comment

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

Is there a syntax error here? GitHub highlights it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It seems to work fine. Could be a problem with the syntax highlighter that GitHub uses.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe because there's no colon or body on the def in the preceding code block?


class SupportsClose(Protocol):
def close(self) -> None:
... # Explicit '...'
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure why this is "Explicit" or why this is significant.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Made the comment more explicit (ha).


close_all([Resource(), open('some/file')]) # Okay!

``Resource`` is a subtype of the ``SupportClose`` protocol since it defines
Copy link
Member

Choose a reason for hiding this comment

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

SupportsClose, not SupportClose


.. code-block:: python

class NewProtocol(SupportsClose): # This is NOT a protocol
Copy link
Member

Choose a reason for hiding this comment

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

To make this clearer, maybe name this class NotAProtocol.

self.left: Optional['SimpleTree'] = None
self.right: Optional['SimpleTree'] = None

root = SimpleTree(0) # type: TreeLike # OK
Copy link
Member

Choose a reason for hiding this comment

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

Use variable annotation here.

@emmatyping
Copy link
Member

This should be rebased on top of the new re-write.

@JukkaL
Copy link
Collaborator Author

JukkaL commented May 29, 2018

This is ready for another round of review.

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

This is way too much to review, I propose to just land it.

def __iter__(self) -> Iterator[T]

``Iterator[T]``
---------------
Copy link
Member

Choose a reason for hiding this comment

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

Maybe because there's no colon or body on the def in the preceding code block?

Copy link
Member

@emmatyping emmatyping left a comment

Choose a reason for hiding this comment

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

I went ahead and skimmed it, didn't see any other obvious issues beyond the note by @gvanrossum.

@JukkaL JukkaL merged commit f95e584 into master May 31, 2018
@msullivan msullivan deleted the doc-updates-2 branch May 31, 2018 19:02
msullivan pushed a commit that referenced this pull request May 31, 2018
Partial list of changes:

* Move a bunch of less core functionality to later in the documentation to
  make it easier to get started with mypy.

* Remove some obsolete things.

* Migrate more examples to use variable annotations.

* Clarify various explanations.

* Address feedback

* Move a few sections around in the table of contents

Also update some section titles.
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.

4 participants