Skip to content

Commit 379a32a

Browse files
committed
vol2: xrefs para outros vols (WIP)
1 parent cd69bb8 commit 379a32a

File tree

8 files changed

+54
-50
lines changed

8 files changed

+54
-50
lines changed

online/cap08.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ https://fpy.li/pep585[PEP 585—Type Hinting Generics In Standard Collections] (
14081408

14091409
Para encerrar nossa discussão de ABCs em dicas de tipo, precisamos falar sobre as ABCs `numbers`.
14101410

1411-
[[numeric_tower_warning]]
1411+
[[numeric_tower_warning_sec]]
14121412
===== A queda da torre numérica
14131413

14141414
O((("numbers package")))((("numeric tower"))) pacote https://fpy.li/4d[`numbers`] define a assim chamada _torre numérica_ (_numeric tower_) descrita na https://fpy.li/pep3141[PEP 3141—A Type Hierarchy for Numbers] (EN).

online/cap09.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ o Mypy 0.770 reclama quando vê múltiplas funções com o mesmo nome.]
11981198
<4> Registra uma nova função para cada tipo que precisa de tratamento especial,
11991199
com uma dica de tipo correspondente no primeiro parâmetro.
12001200
<5> As ABCs em `numbers` são úteis para uso em conjunto com
1201-
`singledispatch`.footnote:[Apesar do alerta em <<numeric_tower_warning>>,
1201+
`singledispatch`.footnote:[Apesar do alerta em <<numeric_tower_warning_sec>>,
12021202
as ABCs de `numbers` não foram descontinuadas, e você as encontra em código de Python 3.]
12031203
<6> `bool` é um _subtipo-de_ `numbers.Integral`,
12041204
mas a lógica de `singledispatch` busca a implementação com o tipo correspondente mais específico,

online/cap13.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2299,7 +2299,7 @@ substituição por protocolos numéricos.
22992299
Como((("static protocols", "numbers ABCS and numeric protocols",
23002300
id="SPnumbers13")))((("numbers ABCs", id="number13")))((("numeric protocols",
23012301
id="numpro13")))((("protocols", "numeric", id="Pnum13"))) vimos em
2302-
<<numeric_tower_warning>>, as ABCs no pacote `numbers` da biblioteca padrão
2302+
<<numeric_tower_warning_sec>>, as ABCs no pacote `numbers` da biblioteca padrão
23032303
funcionam bem para checagem de tipos durante a execução.
23042304

23052305
Se você precisa checar um inteiro, pode usar `isinstance(x, numbers.Integral)`

print/xrefs/xref-other-vols.ipynb

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,10 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 9,
5+
"execution_count": null,
66
"id": "9e0ff8c8-2e08-4144-bb1c-31ae032ad693",
77
"metadata": {},
8-
"outputs": [
9-
{
10-
"name": "stdout",
11-
"output_type": "stream",
12-
"text": [
13-
"../../vol2/cap09.adoc\n"
14-
]
15-
}
16-
],
8+
"outputs": [],
179
"source": [
1810
"from pathlib import Path\n",
1911
"\n",
@@ -37,36 +29,10 @@
3729
},
3830
{
3931
"cell_type": "code",
40-
"execution_count": 15,
32+
"execution_count": null,
4133
"id": "7c21a3dd-ed66-4587-aa51-a443365d346d",
4234
"metadata": {},
43-
"outputs": [
44-
{
45-
"data": {
46-
"text/plain": [
47-
"{'ch_data_model': (1, 1),\n",
48-
" 'ch_sequences': (1, 2),\n",
49-
" 'ch_dicts_sets': (1, 3),\n",
50-
" 'ch_str_bytes': (1, 4),\n",
51-
" 'ch_dataclass': (1, 5),\n",
52-
" 'ch_refs_mut_mem': (1, 6),\n",
53-
" 'ch_func_objects': (1, 7),\n",
54-
" 'ch_type_hints_def': (1, 8),\n",
55-
" 'ch_generators': (3, 17),\n",
56-
" 'ch_with_match': (3, 18),\n",
57-
" 'ch_concurrency_models': (3, 19),\n",
58-
" 'ch_executors': (3, 20),\n",
59-
" 'ch_async': (3, 21),\n",
60-
" 'ch_dynamic_attrs': (3, 22),\n",
61-
" 'ch_descriptors': (3, 23),\n",
62-
" 'ch_class_metaprog': (3, 24)}"
63-
]
64-
},
65-
"execution_count": 15,
66-
"metadata": {},
67-
"output_type": "execute_result"
68-
}
69-
],
35+
"outputs": [],
7036
"source": [
7137
"other_vols = {}\n",
7238
"\n",
@@ -83,7 +49,7 @@
8349
},
8450
{
8551
"cell_type": "code",
86-
"execution_count": 21,
52+
"execution_count": null,
8753
"id": "546fd140-6977-469a-8e32-c7497f09dc27",
8854
"metadata": {},
8955
"outputs": [],
@@ -104,17 +70,51 @@
10470
},
10571
{
10672
"cell_type": "code",
107-
"execution_count": null,
73+
"execution_count": 1,
10874
"id": "87de0cb0-4e90-43af-9eb0-f72874f2cc2a",
10975
"metadata": {},
11076
"outputs": [],
111-
"source": []
77+
"source": [
78+
"from xvol_xrefs import replace_xrefs_to_vols"
79+
]
11280
},
11381
{
11482
"cell_type": "code",
115-
"execution_count": null,
83+
"execution_count": 2,
11684
"id": "552c2fa0-ff72-404b-a7b1-868273c38cb9",
11785
"metadata": {},
86+
"outputs": [
87+
{
88+
"name": "stdout",
89+
"output_type": "stream",
90+
"text": [
91+
"<<prop_validation_sec>> https://pythonfluente.com/2/#prop_validation_sec[«Seção 22.4»] (vol.3)\n",
92+
"<<numeric_tower_warning_sec>> https://pythonfluente.com/2/#numeric_tower_warning_sec[«Seção 8.5.7.1»] (vol.1)\n",
93+
"<<methods_are_descriptors_sec>> https://pythonfluente.com/2/#methods_are_descriptors_sec[«Seção 23.4»] (vol.3)\n"
94+
]
95+
},
96+
{
97+
"ename": "ValueError",
98+
"evalue": "unexpected xref: 'ex_vector2d'",
99+
"output_type": "error",
100+
"traceback": [
101+
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
102+
"\u001b[31mValueError\u001b[39m Traceback (most recent call last)",
103+
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[2]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mreplace_xrefs_to_vols\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
104+
"\u001b[36mFile \u001b[39m\u001b[32m~/flupy/pythonfluente2e/print/xrefs/xvol_xrefs.py:165\u001b[39m, in \u001b[36mreplace_xrefs_to_vols\u001b[39m\u001b[34m()\u001b[39m\n\u001b[32m 163\u001b[39m text = \u001b[33mf\u001b[39m\u001b[33m'\u001b[39m\u001b[33mSeção \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mnumber_str\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m'\u001b[39m\n\u001b[32m 164\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m165\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[33mf\u001b[39m\u001b[33m'\u001b[39m\u001b[33munexpected xref: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mxref\u001b[38;5;132;01m!r}\u001b[39;00m\u001b[33m'\u001b[39m)\n\u001b[32m 166\u001b[39m link = BASE_URL + \u001b[33m'\u001b[39m\u001b[33m#\u001b[39m\u001b[33m'\u001b[39m + xref\n\u001b[32m 167\u001b[39m \u001b[38;5;66;03m#print(f'<<{xref}>>', f'{text} &#91;vol.{volume}, fpy.li{SHORT_URLS[link]}&#93;')\u001b[39;00m\n\u001b[32m 168\u001b[39m \u001b[38;5;66;03m# https://fpy.li/24[«Capítulo 24»] (vol.3)\u001b[39;00m\n",
105+
"\u001b[31mValueError\u001b[39m: unexpected xref: 'ex_vector2d'"
106+
]
107+
}
108+
],
109+
"source": [
110+
"replace_xrefs_to_vols()"
111+
]
112+
},
113+
{
114+
"cell_type": "code",
115+
"execution_count": null,
116+
"id": "bd8f090f-e95d-4005-96ce-160387d3db63",
117+
"metadata": {},
118118
"outputs": [],
119119
"source": []
120120
}

print/xrefs/xvol_xrefs.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def find_git_root():
4747

4848

4949
def list_invalid_xrefs() -> list[str]:
50-
adoc = find_git_root() / 'vol1/vol1.adoc'
50+
adoc = find_git_root() / 'vol2/vol2-cor.adoc'
5151
cmd = f'''asciidoctor -v {adoc} -o lixo'''
5252
result = subprocess.run(cmd, shell=True, stderr=subprocess.PIPE, text=True)
5353
seen = set()
@@ -161,10 +161,14 @@ def replace_xrefs_to_vols():
161161
chapter = numbers[0]
162162
volume = (chapter - 1) // 8 + 1
163163
text = f'Seção {number_str}'
164+
elif xref.startswith('ex_'):
165+
164166
else:
165167
raise ValueError(f'unexpected xref: {xref!r}')
166168
link = BASE_URL + '#' + xref
167-
print(f'<<{xref}>>', f'{text} &#91;vol.{volume}, fpy.li{SHORT_URLS[link]}&#93;')
169+
#print(f'<<{xref}>>', f'{text} &#91;vol.{volume}, fpy.li{SHORT_URLS[link]}&#93;')
170+
# https://fpy.li/24[«Capítulo 24»] (vol.3)
171+
print(f'<<{xref}>>', f'{link}{text}»] (vol.{volume})')
168172

169173

170174
if __name__ == '__main__':

vol1/cap08.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,7 @@ A lista completa de classes que se tornaram genéricas aparece na seção «_Imp
14171417
Para encerrar nossa discussão de ABCs em dicas de tipo, precisamos falar sobre as ABCs numéricas.
14181418

14191419
<<<
1420-
[[numeric_tower_warning]]
1420+
[[numeric_tower_warning_sec]]
14211421
===== A queda da torre numérica
14221422

14231423
O((("numbers package")))((("numeric tower"))) pacote

vol2/cap09.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ o Mypy 0.770 reclama quando vê múltiplas funções com o mesmo nome.]
11981198
<4> Registra uma nova função para cada tipo que precisa de tratamento especial,
11991199
com uma dica de tipo correspondente no primeiro parâmetro.
12001200
<5> As ABCs em `numbers` são úteis para uso em conjunto com
1201-
`singledispatch`.footnote:[Apesar do alerta em <<numeric_tower_warning>>,
1201+
`singledispatch`.footnote:[Apesar do alerta em <<numeric_tower_warning_sec>>,
12021202
as ABCs de `numbers` não foram descontinuadas, e você as encontra em código de Python 3.]
12031203
<6> `bool` é um _subtipo-de_ `numbers.Integral`,
12041204
mas a lógica de `singledispatch` busca a implementação com o tipo correspondente mais específico,

vol2/cap13.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2299,7 +2299,7 @@ substituição por protocolos numéricos.
22992299
Como((("static protocols", "numbers ABCS and numeric protocols",
23002300
id="SPnumbers13")))((("numbers ABCs", id="number13")))((("numeric protocols",
23012301
id="numpro13")))((("protocols", "numeric", id="Pnum13"))) vimos em
2302-
<<numeric_tower_warning>>, as ABCs no pacote `numbers` da biblioteca padrão
2302+
<<numeric_tower_warning_sec>>, as ABCs no pacote `numbers` da biblioteca padrão
23032303
funcionam bem para checagem de tipos durante a execução.
23042304

23052305
Se você precisa checar um inteiro, pode usar `isinstance(x, numbers.Integral)`

0 commit comments

Comments
 (0)