Skip to content

Commit 9f19502

Browse files
realpython-botRPBot
andauthored
Revert repo-wide formatter changes outside the article folder (#803)
A repo-wide `ruff format` run reformatted 14 files belonging to 13 unrelated tutorials. Because pyproject.toml sets target-version = "py314", ruff applied PEP 758 and stripped the parentheses from multi-exception except clauses in 9 published sample files: except (ZeroDivisionError, ValueError): -> except ZeroDivisionError, ValueError: That syntax is valid on Python 3.14 but a SyntaxError on 3.13 and earlier, so those materials would stop running for most readers - and the CI matrix is Python 3.14 only, so it stays green either way. Reverts all 14 files to master. No changes to cursor-vs-copilot-python/. Co-authored-by: RPBot <dan+rpbot@realpython.com>
1 parent 0c60c15 commit 9f19502

14 files changed

Lines changed: 47 additions & 45 deletions

File tree

asyncio-walkthrough/areq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async def parse(url: str, session: ClientSession, **kwargs) -> set:
7474
try:
7575
# Ensure we return an absolute path.
7676
abslink = urllib.parse.urljoin(url, link)
77-
except urllib.error.URLError, ValueError:
77+
except (urllib.error.URLError, ValueError):
7878
logger.exception("Error parsing URL: %s", link)
7979
pass
8080
else:

cursor-vs-windsurf-python/prompts.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ Type this into a file and let each editor complete it:
6262
@dataclass
6363
class RetryMetadata:
6464
attempts_made: int
65-
66-
6765
# ...
6866
```
6967

django-pagination/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Add the Python keywords to your database:
6767
>>> for kw in keyword.kwlist:
6868
... k = Keyword(name=kw)
6969
... k.save()
70+
...
7071
```
7172
7273
Verify that the keywords were added to your database:

flask-connexion-rest-part-2/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Navigate inside the `rp_flask_api/`, enter the [Python interactive shell](https:
5151
>>> for person_data in people:
5252
... insert_cmd = f"INSERT INTO person VALUES ({person_data})"
5353
... conn.execute(insert_cmd)
54+
...
5455
<sqlite3.Cursor object at 0x104ac4dc0>
5556
<sqlite3.Cursor object at 0x104ac4f40>
5657
<sqlite3.Cursor object at 0x104ac4fc0>

flush-print/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ SLIGHTLY_TOO_LARGE_FOR_BUFFER = 80_000
4242
# Script paused at 10919
4343

4444
bufsize = 80_000 - 10919
45-
print(bufsize) # 69081 <-- Your buffer size approximation
45+
print(bufsize) # 69081 <-- Your buffer size approximation
4646
```
4747

4848
You can divide the number you get by `1000` to get an estimation of your buffer size for stdout in kilobytes. In the example above, on a macOS system with a M1 chip, the buffer size of stdout when interacting with it through Python's `print()` would therefore be approximately 69 kilobytes.

python-copy/benchmark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def benchmark(container, executions):
3232
def sliceable(instance):
3333
try:
3434
instance[0:1]
35-
except TypeError, KeyError:
35+
except (TypeError, KeyError):
3636
return False
3737
else:
3838
return True

python-eval-mathrepl/mathrepl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def main():
5353
# Read user's input
5454
try:
5555
expression = input(f"{PS1} ")
56-
except KeyboardInterrupt, EOFError:
56+
except (KeyboardInterrupt, EOFError):
5757
raise SystemExit()
5858

5959
# Handle special commands

python-import/namespace_package/local/serializers/factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def get_serializer(format):
77
try:
88
module = importlib.import_module(f"serializers.{format}")
99
serializer = getattr(module, f"{format.title()}Serializer")
10-
except ImportError, AttributeError:
10+
except (ImportError, AttributeError):
1111
raise ValueError(f"Unknown format {format!r}") from None
1212

1313
return serializer()

python-import/population_quiz/population_quiz.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def run_quiz(population, num_questions, num_countries):
4646
try:
4747
guess_idx = int(guess_str) - 1
4848
guess = countries[guess_idx]
49-
except ValueError, IndexError:
49+
except (ValueError, IndexError):
5050
print(f"Please answer between 1 and {num_countries}")
5151
else:
5252
break
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
try:
22
with open("file.txt", mode="rt") as f:
33
print(f.readlines())
4-
except FileNotFoundError, PermissionError:
4+
except (FileNotFoundError, PermissionError):
55
pass

0 commit comments

Comments
 (0)