@@ -364,7 +364,7 @@ msgid ""
364364"y = eggs"
365365msgstr ""
366366">>> try:\n"
367- "... raise Exception('spam ', 'eggs ')\n"
367+ "... raise Exception('szynka ', 'jajka ')\n"
368368"... except Exception as inst:\n"
369369"... print(type(inst)) # typ wyjątku\n"
370370"... print(inst.args) # argumenty przechowywane w .args\n"
@@ -377,10 +377,10 @@ msgstr ""
377377"... print('y =', y)\n"
378378"...\n"
379379"<class 'Exception'>\n"
380- "('spam ', 'eggs ')\n"
381- "('spam ', 'eggs ')\n"
382- "x = spam \n"
383- "y = eggs "
380+ "('szynka ', 'jajka ')\n"
381+ "('szynka ', 'jajka ')\n"
382+ "x = szynka \n"
383+ "y = jajka "
384384
385385msgid ""
386386"The exception's :meth:`~object.__str__` output is printed as the last part "
@@ -789,6 +789,15 @@ msgid ""
789789" File \" <stdin>\" , line 2, in <module>\n"
790790"KeyboardInterrupt"
791791msgstr ""
792+ ">>> try:\n"
793+ "... raise KeyboardInterrupt\n"
794+ "... finally:\n"
795+ "... print('Żegnaj, świecie!')\n"
796+ "...\n"
797+ "Żegnaj, świecie!\n"
798+ "Traceback (most recent call last):\n"
799+ " File \" <stdin>\" , line 2, in <module>\n"
800+ "KeyboardInterrupt"
792801
793802msgid ""
794803"If a :keyword:`finally` clause is present, the :keyword:`!finally` clause "
@@ -865,6 +874,14 @@ msgid ""
865874">>> bool_return()\n"
866875"False"
867876msgstr ""
877+ ">>> def bool_return():\n"
878+ "... try:\n"
879+ "... return True\n"
880+ "... finally:\n"
881+ "... return False\n"
882+ "...\n"
883+ ">>> bool_return()\n"
884+ "False"
868885
869886msgid "A more complicated example::"
870887msgstr "Bardziej skomplikowany przykład::"
@@ -893,6 +910,28 @@ msgid ""
893910" File \" <stdin>\" , line 3, in divide\n"
894911"TypeError: unsupported operand type(s) for /: 'str' and 'str'"
895912msgstr ""
913+ ">>> def divide(x, y):\n"
914+ "... try:\n"
915+ "... result = x / y\n"
916+ "... except ZeroDivisionError:\n"
917+ "... print(\" dzielenie przez zero!\" )\n"
918+ "... else:\n"
919+ "... print(\" wynik to\" , result)\n"
920+ "... finally:\n"
921+ "... print(\" wykonanie klauzuli finally\" )\n"
922+ "...\n"
923+ ">>> divide(2, 1)\n"
924+ "wynik to 2.0\n"
925+ "wykonanie klauzuli finally\n"
926+ ">>> divide(2, 0)\n"
927+ "dzielenie przez zero!\n"
928+ "wykonanie klauzuli finally\n"
929+ ">>> divide(\" 2\" , \" 1\" )\n"
930+ "wykonanie klauzuli finally\n"
931+ "Traceback (most recent call last):\n"
932+ " File \" <stdin>\" , line 1, in <module>\n"
933+ " File \" <stdin>\" , line 3, in divide\n"
934+ "TypeError: unsupported operand type(s) for /: 'str' and 'str'"
896935
897936msgid ""
898937"As you can see, the :keyword:`finally` clause is executed in any event. "
@@ -933,6 +972,8 @@ msgid ""
933972"for line in open(\" myfile.txt\" ):\n"
934973" print(line, end=\"\" )"
935974msgstr ""
975+ "for line in open(\" moj_plik.txt\" ):\n"
976+ " print(line, end=\"\" )"
936977
937978msgid ""
938979"The problem with this code is that it leaves the file open for an "
@@ -954,6 +995,9 @@ msgid ""
954995" for line in f:\n"
955996" print(line, end=\"\" )"
956997msgstr ""
998+ "with open(\" moj_plik.txt\" ) as f:\n"
999+ " for line in f:\n"
1000+ " print(line, end=\"\" )"
9571001
9581002msgid ""
9591003"After the statement is executed, the file *f* is always closed, even if a "
@@ -1014,6 +1058,27 @@ msgid ""
10141058"caught <class 'ExceptionGroup'>: e\n"
10151059">>>"
10161060msgstr ""
1061+ ">>> def f():\n"
1062+ "... excs = [OSError('błąd 1'), SystemError('błąd 2')]\n"
1063+ "... raise ExceptionGroup('wystąpiły problemy', excs)\n"
1064+ "...\n"
1065+ ">>> f()\n"
1066+ " + Exception Group Traceback (most recent call last):\n"
1067+ " | File \" <stdin>\" , line 1, in <module>\n"
1068+ " | File \" <stdin>\" , line 3, in f\n"
1069+ " | ExceptionGroup: wystąpiły problemy\n"
1070+ " +-+---------------- 1 ----------------\n"
1071+ " | OSError: błąd 1\n"
1072+ " +---------------- 2 ----------------\n"
1073+ " | SystemError: błąd 2\n"
1074+ " +------------------------------------\n"
1075+ ">>> try:\n"
1076+ "... f()\n"
1077+ "... except Exception as e:\n"
1078+ "... print(f'przechwycono {type(e)}: e')\n"
1079+ "...\n"
1080+ "przechwycono <class 'ExceptionGroup'>: e\n"
1081+ ">>>"
10171082
10181083msgid ""
10191084"By using ``except*`` instead of ``except``, we can selectively handle only "
@@ -1066,6 +1131,41 @@ msgid ""
10661131" +------------------------------------\n"
10671132">>>"
10681133msgstr ""
1134+ ">>> def f():\n"
1135+ "... raise ExceptionGroup(\n"
1136+ "... \" grupa 1\" ,\n"
1137+ "... [\n"
1138+ "... OSError(1),\n"
1139+ "... SystemError(2),\n"
1140+ "... ExceptionGroup(\n"
1141+ "... \" grupa 2\" ,\n"
1142+ "... [\n"
1143+ "... OSError(3),\n"
1144+ "... RecursionError(4)\n"
1145+ "... ]\n"
1146+ "... )\n"
1147+ "... ]\n"
1148+ "... )\n"
1149+ "...\n"
1150+ ">>> try:\n"
1151+ "... f()\n"
1152+ "... except* OSError as e:\n"
1153+ "... print(\" Wystąpiły błędy typu OSError\" )\n"
1154+ "... except* SystemError as e:\n"
1155+ "... print(\" Wystąpiły błędy typu SystemError\" )\n"
1156+ "...\n"
1157+ "Wystąpiły błędy typu OSError\n"
1158+ "Wystąpiły błędy typu SystemError\n"
1159+ " + Exception Group Traceback (most recent call last):\n"
1160+ " | File \" <stdin>\" , line 2, in <module>\n"
1161+ " | File \" <stdin>\" , line 2, in f\n"
1162+ " | ExceptionGroup: grupa 1\n"
1163+ " +-+---------------- 1 ----------------\n"
1164+ " | ExceptionGroup: grupa 2\n"
1165+ " +-+---------------- 1 ----------------\n"
1166+ " | RecursionError: 4\n"
1167+ " +------------------------------------\n"
1168+ ">>>"
10691169
10701170msgid ""
10711171"Note that the exceptions nested in an exception group must be instances, not "
@@ -1090,6 +1190,16 @@ msgid ""
10901190"... raise ExceptionGroup(\" Test Failures\" , excs)\n"
10911191"..."
10921192msgstr ""
1193+ ">>> excs = []\n"
1194+ "... for test in tests:\n"
1195+ "... try:\n"
1196+ "... test.run()\n"
1197+ "... except Exception as e:\n"
1198+ "... excs.append(e)\n"
1199+ "...\n"
1200+ ">>> if excs:\n"
1201+ "... raise ExceptionGroup(\" Niepowodzenia testów\" , excs)\n"
1202+ "..."
10931203
10941204msgid "Enriching Exceptions with Notes"
10951205msgstr "Wzbogacanie wyjątków o notatki"
@@ -1125,6 +1235,19 @@ msgid ""
11251235"Add some more information\n"
11261236">>>"
11271237msgstr ""
1238+ ">>> try:\n"
1239+ "... raise TypeError('niepoprawny typ')\n"
1240+ "... except Exception as e:\n"
1241+ "... e.add_note('Dodatkowa informacja')\n"
1242+ "... e.add_note('Więcej dodatkowej informacji')\n"
1243+ "... raise\n"
1244+ "...\n"
1245+ "Traceback (most recent call last):\n"
1246+ " File \" <stdin>\" , line 2, in <module>\n"
1247+ "TypeError: niepoprawny typ\n"
1248+ "Dodatkowa informacja\n"
1249+ "Więcej dodatkowej informacji\n"
1250+ ">>>"
11281251
11291252msgid ""
11301253"For example, when collecting exceptions into an exception group, we may want "
@@ -1172,3 +1295,38 @@ msgid ""
11721295" +------------------------------------\n"
11731296">>>"
11741297msgstr ""
1298+ ">>> def f():\n"
1299+ "... raise OSError('operacja się nie powiodła')\n"
1300+ "...\n"
1301+ ">>> excs = []\n"
1302+ ">>> for i in range(3):\n"
1303+ "... try:\n"
1304+ "... f()\n"
1305+ "... except Exception as e:\n"
1306+ "... e.add_note(f'Wystąpiło w iteracji {i+1}')\n"
1307+ "... excs.append(e)\n"
1308+ "...\n"
1309+ ">>> raise ExceptionGroup('Napotkaliśmy problemy', excs)\n"
1310+ " + Exception Group Traceback (most recent call last):\n"
1311+ " | File \" <stdin>\" , line 1, in <module>\n"
1312+ " | ExceptionGroup: Napotkaliśmy problemy (3 sub-exceptions)\n"
1313+ " +-+---------------- 1 ----------------\n"
1314+ " | Traceback (most recent call last):\n"
1315+ " | File \" <stdin>\" , line 3, in <module>\n"
1316+ " | File \" <stdin>\" , line 2, in f\n"
1317+ " | OSError: operacja się nie powiodła\n"
1318+ " | Wystąpiło w iteracji 1\n"
1319+ " +---------------- 2 ----------------\n"
1320+ " | Traceback (most recent call last):\n"
1321+ " | File \" <stdin>\" , line 3, in <module>\n"
1322+ " | File \" <stdin>\" , line 2, in f\n"
1323+ " | OSError: operacja się nie powiodła\n"
1324+ " | Wystąpiło w iteracji 2\n"
1325+ " +---------------- 3 ----------------\n"
1326+ " | Traceback (most recent call last):\n"
1327+ " | File \" <stdin>\" , line 3, in <module>\n"
1328+ " | File \" <stdin>\" , line 2, in f\n"
1329+ " | OSError: operacja się nie powiodła\n"
1330+ " | Wystąpiło w iteracji 3\n"
1331+ " +------------------------------------\n"
1332+ ">>>"
0 commit comments