From 77938e0ba6ecae3862985a3c3cdc6af1c4045f70 Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Mon, 25 Sep 2017 09:17:47 +0300 Subject: [PATCH 1/9] README.md: rearrange first paragraph to be more friendly --- README.md | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index b42a4edfa9c8..f07c44352add 100644 --- a/README.md +++ b/README.md @@ -25,17 +25,8 @@ What is mypy? ------------- Mypy is an optional static type checker for Python. You can add type -hints to your Python programs using the standard for type -annotations introduced in Python 3.5 ([PEP 484](https://www.python.org/dev/peps/pep-0484/)), and use mypy to -type check them statically. Find bugs in your programs without even -running them! - -The type annotation standard has also been backported to earlier -Python 3.x versions. Mypy supports Python 3.3 and later. -XML based reports do not work on Python 3.3 and 3.4 on Windows. - -For Python 2.7, you can add annotations as comments (this is also -specified in [PEP 484](https://www.python.org/dev/peps/pep-0484/)). +hints to your Python programs, and use mypy to type check them statically. +Find bugs in your programs without even running them! You can mix dynamic and static typing in your programs. You can always fall back to dynamic typing when static typing is not convenient, such @@ -56,6 +47,17 @@ def fib(n: int) -> Iterator[int]: Mypy is in development; some features are missing and there are bugs. See 'Development status' below. +Annotations +----------- +You can add type hints to your Python programs using the standard for type +annotations introduced in Python 3.5 ([PEP 484](https://www.python.org/dev/peps/pep-0484/)). +The type annotation standard has also been backported to earlier +Python 3.x versions. Mypy supports Python 3.3 and later. +XML based reports do not work on Python 3.3 and 3.4 on Windows. + +For Python 2.7, you can add annotations as comments (this is also +specified in [PEP 484](https://www.python.org/dev/peps/pep-0484/)). + Requirements ------------ From 43f3988a3bbb23a2fbb2bb89fb1dc5429a7e1c08 Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Mon, 25 Sep 2017 22:47:34 +0300 Subject: [PATCH 2/9] Demonstration for comments and new style annotations --- README.md | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f07c44352add..1189c7f28a10 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,8 @@ Here is a small example to whet your appetite: from typing import Iterator def fib(n: int) -> Iterator[int]: - a, b = 0, 1 + a: int = 0 + b: int = 1 while a < n: yield a a, b = b, a + b @@ -49,14 +50,21 @@ See 'Development status' below. Annotations ----------- -You can add type hints to your Python programs using the standard for type -annotations introduced in Python 3.5 ([PEP 484](https://www.python.org/dev/peps/pep-0484/)). -The type annotation standard has also been backported to earlier -Python 3.x versions. Mypy supports Python 3.3 and later. -XML based reports do not work on Python 3.3 and 3.4 on Windows. +For Python 3, you can add type hints to your Python programs using the standard for type +annotations ([PEP 484](https://www.python.org/dev/peps/pep-0484/)). For Python 2.7, you can add annotations as comments (this is also -specified in [PEP 484](https://www.python.org/dev/peps/pep-0484/)). +specified in [PEP 484](https://www.python.org/dev/peps/pep-0484/)): +```python +from typing import Iterator + +def fib(n): # type: int -> Iterator[int] + a = 0 # type: int + b = 1 # type: int + while a < n: + yield a + a, b = b, a + b +``` Requirements @@ -160,7 +168,8 @@ In Windows, the script is generally installed in C:\>\Python34\python \Python34\Scripts\mypy PROGRAM If you are on Windows using Python 3.3 or 3.4, and would like to use XML reports -download LXML from [PyPi](https://pypi.python.org/pypi/lxml). +download LXML from [PyPi](https://pypi.python.org/pypi/lxml). +XML based reports do not work on Python 3.3 and 3.4 on Windows. ### Working with `virtualenv` From 998e4c3c463d728f310d689ae2b0ef7ffae2bcd5 Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Mon, 25 Sep 2017 22:56:26 +0300 Subject: [PATCH 3/9] Remove erroneous statement --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 1189c7f28a10..f4093a2d7b7e 100644 --- a/README.md +++ b/README.md @@ -168,8 +168,7 @@ In Windows, the script is generally installed in C:\>\Python34\python \Python34\Scripts\mypy PROGRAM If you are on Windows using Python 3.3 or 3.4, and would like to use XML reports -download LXML from [PyPi](https://pypi.python.org/pypi/lxml). -XML based reports do not work on Python 3.3 and 3.4 on Windows. +download LXML from [PyPi](https://pypi.python.org/pypi/lxml). ### Working with `virtualenv` From 932aa4d5eda998fb409ebccc2f833e772dbbddd0 Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Mon, 25 Sep 2017 23:34:03 +0300 Subject: [PATCH 4/9] Remove variable annotations. Change description of annotations Smaller example for python2; only show the difference --- README.md | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index f4093a2d7b7e..56f0828828a1 100644 --- a/README.md +++ b/README.md @@ -38,34 +38,23 @@ Here is a small example to whet your appetite: from typing import Iterator def fib(n: int) -> Iterator[int]: - a: int = 0 - b: int = 1 + a, b = 0, 1 while a < n: yield a a, b = b, a + b ``` +This example uses Python 3 style of the standard type annotations, defined in [PEP 484](https://www.python.org/dev/peps/pep-0484/). -Mypy is in development; some features are missing and there are bugs. -See 'Development status' below. - -Annotations ------------ -For Python 3, you can add type hints to your Python programs using the standard for type -annotations ([PEP 484](https://www.python.org/dev/peps/pep-0484/)). - -For Python 2.7, you can add annotations as comments (this is also -specified in [PEP 484](https://www.python.org/dev/peps/pep-0484/)): +For Python 2.7, the standard annotations are written as comments: ```python -from typing import Iterator - -def fib(n): # type: int -> Iterator[int] - a = 0 # type: int - b = 1 # type: int - while a < n: - yield a - a, b = b, a + b +def reverse(s): # type: str -> str + return s[::-1] ``` +See [the documentation](http://mypy.readthedocs.io/en/stable/introduction.html) for more examples. + +Mypy is in development; some features are missing and there are bugs. +See 'Development status' below. Requirements ------------ From 5422d17230cf3511c23cb0acdbffe9bb831040cf Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Wed, 27 Sep 2017 00:06:02 +0300 Subject: [PATCH 5/9] move PEP-484 link and type comment; deep link for Python 2 --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 56f0828828a1..c39f68a8a216 100644 --- a/README.md +++ b/README.md @@ -25,14 +25,14 @@ What is mypy? ------------- Mypy is an optional static type checker for Python. You can add type -hints to your Python programs, and use mypy to type check them statically. +hints ([PEP 484](https://www.python.org/dev/peps/pep-0484/)) to your Python programs, and use mypy to type check them statically. Find bugs in your programs without even running them! You can mix dynamic and static typing in your programs. You can always fall back to dynamic typing when static typing is not convenient, such as for legacy code. -Here is a small example to whet your appetite: +Here is a small example to whet your appetite (Python 3): ```python from typing import Iterator @@ -43,15 +43,16 @@ def fib(n: int) -> Iterator[int]: yield a a, b = b, a + b ``` -This example uses Python 3 style of the standard type annotations, defined in [PEP 484](https://www.python.org/dev/peps/pep-0484/). +See [the documentation](http://mypy.readthedocs.io/en/stable/introduction.html) for more examples. For Python 2.7, the standard annotations are written as comments: ```python -def reverse(s): # type: str -> str +def reverse(s): + # type: str -> str return s[::-1] ``` -See [the documentation](http://mypy.readthedocs.io/en/stable/introduction.html) for more examples. +See [the documentation for Python 2 support](http://mypy.readthedocs.io/en/latest/python2.html). Mypy is in development; some features are missing and there are bugs. See 'Development status' below. From 8ed7f76a9ca519e98ac064fcf430c3bfca59bc59 Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Wed, 27 Sep 2017 00:13:51 +0300 Subject: [PATCH 6/9] Remove mention of LXML as per @ethanhs comment --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index c39f68a8a216..617754bdf596 100644 --- a/README.md +++ b/README.md @@ -157,9 +157,6 @@ In Windows, the script is generally installed in C:\>\Python34\python \Python34\Scripts\mypy PROGRAM -If you are on Windows using Python 3.3 or 3.4, and would like to use XML reports -download LXML from [PyPi](https://pypi.python.org/pypi/lxml). - ### Working with `virtualenv` If you are using [`virtualenv`](https://virtualenv.pypa.io/en/stable/), From db8e6dff0020c668703be13a765e4fe71a466f0d Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Wed, 27 Sep 2017 00:16:28 +0300 Subject: [PATCH 7/9] Fix type comment and give better example --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 617754bdf596..e7e7a09903cd 100644 --- a/README.md +++ b/README.md @@ -47,9 +47,9 @@ See [the documentation](http://mypy.readthedocs.io/en/stable/introduction.html) For Python 2.7, the standard annotations are written as comments: ```python -def reverse(s): - # type: str -> str - return s[::-1] +def is_palindrome(s): + # type: (str) -> str + return s == s[::-1] ``` See [the documentation for Python 2 support](http://mypy.readthedocs.io/en/latest/python2.html). From e2b9b94700bc8d2c4974981aef7cedb593db6d13 Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Wed, 27 Sep 2017 00:19:28 +0300 Subject: [PATCH 8/9] s/str/bool/ oops --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e7e7a09903cd..e90f3ca9a2c7 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ See [the documentation](http://mypy.readthedocs.io/en/stable/introduction.html) For Python 2.7, the standard annotations are written as comments: ```python def is_palindrome(s): - # type: (str) -> str + # type: (str) -> bool return s == s[::-1] ``` From 09c10557d6709503bb286ac1a67025a85ebe4ac4 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Tue, 26 Sep 2017 14:22:03 -0700 Subject: [PATCH 9/9] Wrap long line. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e90f3ca9a2c7..18c726cd9d0c 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,8 @@ What is mypy? ------------- Mypy is an optional static type checker for Python. You can add type -hints ([PEP 484](https://www.python.org/dev/peps/pep-0484/)) to your Python programs, and use mypy to type check them statically. +hints ([PEP 484](https://www.python.org/dev/peps/pep-0484/)) to your +Python programs, and use mypy to type check them statically. Find bugs in your programs without even running them! You can mix dynamic and static typing in your programs. You can always