Commit bad8647
committed
gh-140039: Improve ZoneInfo error messages with detailed guidance
This commit enhances the error messages when a timezone key is not found
in the zoneinfo module by using PEP-678 exception notes to provide clear,
actionable guidance to users.
Key improvements:
- Uses PEP-678 add_note() for better error message formatting
- Checks if tzdata package is actually missing before suggesting installation
- Provides different messages for missing tzdata vs incorrect timezone keys
- Uses hyphens instead of unicode bullet points for better compatibility
- Changes 'e.g.' to 'for example' for clarity
- Removes OS timezone data message that was confusing for Windows users
The error message now intelligently detects whether:
1. tzdata is not installed (suggests: pip install tzdata)
2. tzdata is installed but key is wrong (suggests: verify the key)
This makes debugging timezone issues much easier for Python developers.1 parent 38c814a commit bad8647
File tree
2 files changed
+26
-18
lines changed- Lib/zoneinfo
- Misc/NEWS.d/next/Library
2 files changed
+26
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
31 | 42 | | |
32 | 43 | | |
33 | 44 | | |
| |||
177 | 188 | | |
178 | 189 | | |
179 | 190 | | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
0 commit comments