Skip to content

Commit 01e717b

Browse files
committed
updated from Atlas
1 parent cbd1388 commit 01e717b

File tree

96 files changed

+579
-1020
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+579
-1020
lines changed

02-array-seq/lispy/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,14 @@ The copyright holder is Peter Norvig and the code is licensed under the
2323
[MIT license](https://github.com/norvig/pytudes/blob/60168bce8cdfacf57c92a5b2979f0b2e95367753/LICENSE).
2424

2525

26+
## Changes to Norvig's code
27+
28+
I made small changes to the programs in `original/`:
29+
30+
* In `lis.py`:
31+
* The `Procedure` class accepts a list of expressions as the `body`, and `__call__` evaluates those expressions in order, and returns the value of the last. This is consistent with Scheme's `lambda` syntax and provided a useful example for pattern matching.
32+
* In the `elif` block for `'lambda'`, I added the `*` in front of the `*body` variable in the tuple unpacking to capture the expressions as a list, before calling the `Procedure` constructor.
33+
34+
* In `lispy.py` I made [changes and a pull request](https://github.com/norvig/pytudes/pull/106) to make it run on Python 3.
35+
2636
_Luciano Ramalho<br/>June 29, 2021_

04-text-byte/charfinder/README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Test ``find`` with single result::
5858

5959
Test ``find`` with two results::
6060

61-
>>> find('chess', 'queen', last=0xFFFF) # doctest:+NORMALIZE_WHITESPACE
61+
>>> find('chess', 'queen', end=0xFFFF) # doctest:+NORMALIZE_WHITESPACE
6262
U+2655 ♕ WHITE CHESS QUEEN
6363
U+265B ♛ BLACK CHESS QUEEN
6464

04-text-byte/charfinder/cf.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import sys
33
import unicodedata
44

5-
FIRST, LAST = ord(' '), sys.maxunicode # <1>
5+
START, END = ord(' '), sys.maxunicode + 1 # <1>
66

7-
def find(*query_words, first=FIRST, last=LAST): # <2>
7+
def find(*query_words, start=START, end=END): # <2>
88
query = {w.upper() for w in query_words} # <3>
9-
for code in range(first, last + 1):
9+
for code in range(start, end):
1010
char = chr(code) # <4>
1111
name = unicodedata.name(char, None) # <5>
1212
if name and query.issubset(name.split()): # <6>

05-data-classes/dataclass/club.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
from dataclasses import dataclass, field
22

3-
43
@dataclass
54
class ClubMember:
6-
75
name: str
86
guests: list = field(default_factory=list)
97

05-data-classes/dataclass/club_wrong.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# tag::CLUBMEMBER[]
44
@dataclass
55
class ClubMember:
6-
76
name: str
87
guests: list = []
98
# end::CLUBMEMBER[]

05-data-classes/dataclass/hackerclub.py

-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434

3535
@dataclass
3636
class HackerClubMember(ClubMember): # <1>
37-
3837
all_handles = set() # <2>
39-
4038
handle: str = '' # <3>
4139

4240
def __post_init__(self):

05-data-classes/dataclass/hackerclub_annotated.py

-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@
3535

3636
@dataclass
3737
class HackerClubMember(ClubMember):
38-
3938
all_handles: ClassVar[set[str]] = set()
40-
4139
handle: str = ''
4240

4341
def __post_init__(self):

05-data-classes/dataclass/resource.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from datetime import date
3333

3434

35-
class ResourceType(Enum): # <1>
35+
class ResourceType(Enum): # <1>
3636
BOOK = auto()
3737
EBOOK = auto()
3838
VIDEO = auto()

05-data-classes/meaning/demo_dc.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
@dataclass
44
class DemoDataClass:
5-
65
a: int # <1>
76
b: float = 1.1 # <2>
87
c = 'spam' # <3>

05-data-classes/meaning/demo_nt.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import typing
22

33
class DemoNTClass(typing.NamedTuple):
4-
54
a: int # <1>
65
b: float = 1.1 # <2>
76
c = 'spam' # <3>

05-data-classes/meaning/demo_plain.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
class DemoPlainClass:
2-
32
a: int # <1>
43
b: float = 1.1 # <2>
54
c = 'spam' # <3>

05-data-classes/typing_namedtuple/coordinates.py

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from typing import NamedTuple
1212

1313
class Coordinate(NamedTuple):
14-
1514
lat: float
1615
lon: float
1716

05-data-classes/typing_namedtuple/coordinates2.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
from typing import NamedTuple
1414

1515
class Coordinate(NamedTuple):
16-
1716
lat: float # <1>
1817
lon: float
1918
reference: str = 'WGS84' # <2>
20-
# end::COORDINATE[]
19+
# end::COORDINATE[]

05-data-classes/typing_namedtuple/nocheck_demo.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import typing
22

33
class Coordinate(typing.NamedTuple):
4-
54
lat: float
65
lon: float
76

07-1class-func/clip.py

-48
This file was deleted.

07-1class-func/clip_introspection.rst

-9
This file was deleted.

07-1class-func/clip_signature.rst

-12
This file was deleted.

08-def-type-hints/RPN_calc/calc.py

-67
This file was deleted.

08-def-type-hints/RPN_calc/calc_test.py

-51
This file was deleted.

08-def-type-hints/charindex.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import sys
1616
import re
1717
import unicodedata
18-
from typing import Dict, Set, Iterator
18+
from collections.abc import Iterator
1919

2020
RE_WORD = re.compile(r'\w+')
2121
STOP_CODE = sys.maxunicode + 1
@@ -25,8 +25,8 @@ def tokenize(text: str) -> Iterator[str]: # <1>
2525
for match in RE_WORD.finditer(text):
2626
yield match.group().upper()
2727

28-
def name_index(start: int = 32, end: int = STOP_CODE) -> Dict[str, Set[str]]:
29-
index: Dict[str, Set[str]] = {} # <2>
28+
def name_index(start: int = 32, end: int = STOP_CODE) -> dict[str, set[str]]:
29+
index: dict[str, set[str]] = {} # <2>
3030
for char in (chr(i) for i in range(start, end)):
3131
if name := unicodedata.name(char, ''): # <3>
3232
for word in tokenize(name):

08-def-type-hints/colors.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Tuple, Mapping
1+
from collections.abc import Mapping
22

33
NAMES = {
44
'aqua': 65535,
@@ -19,15 +19,15 @@
1919
'yellow': 16776960,
2020
}
2121

22-
def rgb2hex(color=Tuple[int, int, int]) -> str:
22+
def rgb2hex(color: tuple[int, int, int]) -> str:
2323
if any(c not in range(256) for c in color):
2424
raise ValueError('Color components must be in range(256)')
2525
values = (f'{n % 256:02x}' for n in color)
2626
return '#' + ''.join(values)
2727

2828
HEX_ERROR = "Color must use format '#0099ff', got: {!r}"
2929

30-
def hex2rgb(color=str) -> Tuple[int, int, int]:
30+
def hex2rgb(color: str) -> tuple[int, int, int]:
3131
if len(color) != 7 or color[0] != '#':
3232
raise ValueError(HEX_ERROR.format(color))
3333
try:

08-def-type-hints/columnize.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# tag::COLUMNIZE[]
2-
from typing import Sequence, List, Tuple
2+
from collections.abc import Sequence
33

4-
def columnize(sequence: Sequence[str], num_columns: int = 0) -> List[Tuple[str, ...]]:
4+
def columnize(sequence: Sequence[str], num_columns: int = 0) -> list[tuple[str, ...]]:
55
if num_columns == 0:
66
num_columns = round(len(sequence) ** .5)
77
num_rows, reminder = divmod(len(sequence), num_columns)

0 commit comments

Comments
 (0)