Skip to content

Commit 43f3988

Browse files
authored
Demonstration for comments and new style annotations
1 parent 77938e0 commit 43f3988

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

README.md

+17-8
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ Here is a small example to whet your appetite:
3838
from typing import Iterator
3939

4040
def fib(n: int) -> Iterator[int]:
41-
a, b = 0, 1
41+
a: int = 0
42+
b: int = 1
4243
while a < n:
4344
yield a
4445
a, b = b, a + b
@@ -49,14 +50,21 @@ See 'Development status' below.
4950

5051
Annotations
5152
-----------
52-
You can add type hints to your Python programs using the standard for type
53-
annotations introduced in Python 3.5 ([PEP 484](https://www.python.org/dev/peps/pep-0484/)).
54-
The type annotation standard has also been backported to earlier
55-
Python 3.x versions. Mypy supports Python 3.3 and later.
56-
XML based reports do not work on Python 3.3 and 3.4 on Windows.
53+
For Python 3, you can add type hints to your Python programs using the standard for type
54+
annotations ([PEP 484](https://www.python.org/dev/peps/pep-0484/)).
5755

5856
For Python 2.7, you can add annotations as comments (this is also
59-
specified in [PEP 484](https://www.python.org/dev/peps/pep-0484/)).
57+
specified in [PEP 484](https://www.python.org/dev/peps/pep-0484/)):
58+
```python
59+
from typing import Iterator
60+
61+
def fib(n): # type: int -> Iterator[int]
62+
a = 0 # type: int
63+
b = 1 # type: int
64+
while a < n:
65+
yield a
66+
a, b = b, a + b
67+
```
6068

6169

6270
Requirements
@@ -160,7 +168,8 @@ In Windows, the script is generally installed in
160168
C:\>\Python34\python \Python34\Scripts\mypy PROGRAM
161169

162170
If you are on Windows using Python 3.3 or 3.4, and would like to use XML reports
163-
download LXML from [PyPi](https://pypi.python.org/pypi/lxml).
171+
download LXML from [PyPi](https://pypi.python.org/pypi/lxml).
172+
XML based reports do not work on Python 3.3 and 3.4 on Windows.
164173

165174
### Working with `virtualenv`
166175

0 commit comments

Comments
 (0)