-
-
Notifications
You must be signed in to change notification settings - Fork 3k
More improvements to cheat sheet #1659
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
Conversation
# Mapping is an abtract base class for a dict-type thing that may | ||
# not support writing to the mapping | ||
# A generator function that yields ints is secretly just a function that | ||
# returns an iterable (see below) of ints, so that's how we annotate it. |
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.
Technically it's an Iterator. Not sure if this distinction matters, given that Iterator inherits from Iterable.
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.
Yeah. I wrote Iterator first for that reason, then contemplated explaining the distinction between Iterator and Iterable (having already recommended Iterable elsewhere), and concluded there isn't a good explanation in this context because the distinction doesn't actually matter.
Also, we really need to have a PY3 version of this... |
@@ -1,7 +1,7 @@ | |||
Mypy syntax cheat sheet (Python 2) | |||
================================== | |||
|
|||
This document is a quick cheat sheet showing how the PEP-484 type | |||
This document is a quick cheat sheet showing how the PEP 484 type |
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.
Make PEP 484 a link
We now install typed_ast from PyPI as part of CI so we can run fast parser tests... and it doesn't build on Windows yet. :( |
|
||
|
||
Standard duck types / ABCs | ||
************************** |
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.
you probably want to expand what those titles mean. Most people writing Python code don't know those terms.
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.
(Maybe with a link)
Thanks for all the review! Pushed a new version. The comments that pointed out additional things we should cover, I added if they seemed pretty tricky to explain and otherwise I added as TODO items or will make issues for -- I want to start populating a "for newcomers" label on issues, composed mainly of easy fixes to documentation and the like. Lasse showed me how coala does this (see the issues at http://tinyurl.com/coala-new), and they've made very good use of it. |
I made a revision pass through the whole document, and made several kinds of changes: * Organize it all in hopes of making things easier to find with thematic groupings, headers, spacing, and putting the key words at the start of each description. * Give the descriptions more of a common style. * Explain a few things like `reveal_type` and `Sequence` a little more fully. * Cut the redundant `Tuple` example. * Add descriptions for the class-definition example. * Add a description for the generator-function example, and change its return-type annotation from `Iterator` to `Iterable`. That gets us out of trying to explain the difference between those, as `Iterable` is the one we mention elsewhere for function parameters. And as far as I can see, there isn't a reason we need to recommend `Iterator` instead here. I'd have liked also to switch from recommending `six.text_type` to `typing.Text`, but that should wait until 3.5.2, with `Text`, is out.
(Rebased to pick up Guido's disabling of AppVeyor.) |
Somehow the appveyor.yml file still wreaked havoc; I've ignored it. |
I made a revision pass through the whole document, and made several
kinds of changes:
thematic groupings, headers, spacing, and putting the key words at
the start of each description.
reveal_type
andSequence
a little morefully.
Tuple
example.return-type annotation from
Iterator
toIterable
. That gets usout of trying to explain the difference between those, as
Iterable
is the one we mention elsewhere for function parameters. And as far
as I can see, there isn't a reason we need to recommend
Iterator
instead here.
I'd have liked also to switch from recommending
six.text_type
totyping.Text
, but that should wait until 3.5.2, withText
, is out./cc @timabbott -- re-revisions welcome!