Skip to content

Commit da27b21

Browse files
heikkitoivonencodex
andcommitted
Fix: Complete remaining stdlib correctness audit
Co-Authored-By: Codex <codex@openai.com>
1 parent acf5553 commit da27b21

7 files changed

Lines changed: 33 additions & 63 deletions

File tree

docs/stdlib/asynchat.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,6 @@ async def main():
323323
## Related Documentation
324324

325325
- [asyncio Module](asyncio.md) - **USE THIS INSTEAD**
326-
- [asyncore Module](asyncore.md) - Also deprecated
326+
- [asyncore Module](asyncore.md) - Also removed in 3.12
327327
- [socket Module](socket.md) - Low-level sockets
328328
- [concurrent.futures Module](concurrent_futures.md) - Alternative for concurrency

docs/stdlib/asyncore.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ async def main():
345345

346346
# asyncio event loop (MODERN):
347347
# - Uses best available: epoll/kqueue/IOCP
348-
# - O(log m) to check ready sockets
348+
# - Readiness handling is implementation-dependent (not a simple O(log m) rule)
349349
# - Scales to thousands of connections
350350
# - Coroutine-based (async/await)
351351
```
@@ -360,6 +360,6 @@ async def main():
360360
## Related Documentation
361361

362362
- [asyncio Module](asyncio.md) - **USE THIS INSTEAD**
363-
- [asynchat Module](asynchat.md) - Also deprecated
363+
- [asynchat Module](asynchat.md) - Also removed in 3.12
364364
- [selectors Module](selectors.md) - Low-level multiplexed I/O
365365
- [socket Module](socket.md) - Low-level sockets

docs/stdlib/cgi.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ The `cgi` module provides utilities for parsing CGI (Common Gateway Interface) f
1818
### Query String Parsing
1919

2020
```python
21-
import cgi
2221
from urllib.parse import parse_qs, parse_qsl
2322

2423
# Modern approach (use urllib.parse instead)
@@ -97,7 +96,8 @@ def main():
9796
name = form.getvalue('name', 'Guest')
9897

9998
# Generate response
100-
print(f"<h1>Hello, {cgi.escape(name)}!</h1>")
99+
from html import escape
100+
print(f"<h1>Hello, {escape(name)}!</h1>")
101101

102102
if __name__ == "__main__":
103103
main()
@@ -202,6 +202,6 @@ form = cgi.FieldStorage()
202202
## Related Modules
203203

204204
- [urllib.parse Module](urllib.md) - URL parsing and encoding
205-
- [html Module](#) - HTML utilities
205+
- [html Module](html.md) - HTML utilities
206206
- [urllib.request Module](urllib.md) - URL requests
207207
- [wsgiref Module](wsgiref.md) - WSGI reference implementation

docs/stdlib/cgitb.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ cgitb.enable()
231231
## Best Practices
232232

233233
```python
234-
#DO: Use error handling in development
234+
#Legacy only (Python <= 3.12): use cgitb in development
235235
import cgitb
236236
cgitb.enable() # Use only in development
237237

@@ -253,4 +253,4 @@ print("<p>An error occurred. Please try again later.</p>")
253253
- [logging Module](logging.md) - Error logging
254254
- [traceback Module](traceback.md) - Traceback handling
255255
- [sys Module](sys.md) - System information
256-
- [html Module](#) - HTML utilities
256+
- [html Module](html.md) - HTML utilities

docs/stdlib/imp.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# imp Module
22

3-
The `imp` module provides functions for importing modules. This module is deprecated since Python 3.4 and removed in Python 3.12.
3+
⚠️ **REMOVED IN PYTHON 3.12**: The `imp` module was deprecated since Python 3.4 and removed in Python 3.12.
44

5-
## Deprecation Notice
5+
The `imp` module provided functions for importing modules.
6+
7+
## Removal Notice
68

79
```python
810
# ❌ DON'T: Use imp module (deprecated, removed in 3.12)
@@ -223,5 +225,5 @@ print(config.DATABASE_URL)
223225

224226
- [importlib Module](importlib.md) - Modern import machinery
225227
- [sys Module](sys.md) - System module list
226-
- [importlib.util Module](#) - Utility functions
228+
- [importlib Module](importlib.md) - Utility functions (`importlib.util`)
227229
- [pathlib Module](pathlib.md) - File path handling

docs/stdlib/lib2to3.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# lib2to3 Module
22

3-
The `lib2to3` module provides tools for converting Python 2 code to Python 3, using a refactoring framework with syntax tree transformations.
3+
⚠️ **REMOVED IN PYTHON 3.13**: The `lib2to3` module and `2to3` tool were deprecated in Python 3.11 and removed in Python 3.13.
4+
5+
The `lib2to3` module provided tools for converting Python 2 code to Python 3, using a refactoring framework with syntax tree transformations.
46

57
## Complexity Reference
68

@@ -15,7 +17,7 @@ The `lib2to3` module provides tools for converting Python 2 code to Python 3, us
1517
### Using 2to3 Tool
1618

1719
```bash
18-
# Command-line usage
20+
# Legacy command-line usage (Python <= 3.12)
1921
2to3 -w script.py # Convert in place
2022
2to3 -d script.py # Dry run (show diffs)
2123
2to3 -f all script.py # Apply all fixers
@@ -25,6 +27,7 @@ The `lib2to3` module provides tools for converting Python 2 code to Python 3, us
2527
### Programmatic Conversion
2628

2729
```python
30+
# Legacy API usage (Python <= 3.12)
2831
from lib2to3 import refactor
2932

3033
# Create refactoring tool - O(1)

docs/stdlib/sndhdr.md

Lines changed: 15 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# sndhdr Module
22

3-
The `sndhdr` module identifies the format of sound files and returns information about sound file headers. This module is deprecated and removed in Python 3.13.
3+
⚠️ **REMOVED IN PYTHON 3.13**: The `sndhdr` module was deprecated in Python 3.11 and removed in Python 3.13.
44

5-
## Deprecation Notice
5+
The `sndhdr` module identified the format of sound files and returned information about sound file headers.
6+
7+
## Removal Notice
68

79
```python
810
# ❌ DON'T: Use sndhdr (deprecated, removed in 3.13)
@@ -14,7 +16,6 @@ info = sndhdr.what('sound.au')
1416
# - soundfile library
1517
# - audioread library
1618
# - wave module (for WAV files)
17-
# - sunau module (for AU files)
1819
```
1920

2021
## Complexity Reference
@@ -76,37 +77,6 @@ print(f"Duration: {info['duration']:.2f} seconds")
7677
print(f"Sample rate: {info['sample_rate']} Hz")
7778
```
7879

79-
### Using sunau Module (Built-in)
80-
81-
```python
82-
# ✅ RECOMMENDED: Use sunau for AU files
83-
import sunau
84-
85-
def inspect_au(filepath):
86-
"""
87-
Inspect AU sound file header.
88-
89-
Time: O(1)
90-
Space: O(1)
91-
"""
92-
with sunau.open(filepath, 'rb') as f:
93-
# Get parameters - O(1)
94-
(channels, sample_width, sample_rate, nframes, compression, compression_name) = f.getparams()
95-
96-
return {
97-
'channels': channels,
98-
'sample_width': sample_width,
99-
'sample_rate': sample_rate,
100-
'frames': nframes,
101-
'compression': compression_name,
102-
'duration': nframes / sample_rate if sample_rate > 0 else 0
103-
}
104-
105-
info = inspect_au('audio.au')
106-
print(f"Compression: {info['compression']}")
107-
print(f"Duration: {info['duration']:.2f} seconds")
108-
```
109-
11080
### Using scipy (Third-party)
11181

11282
```python
@@ -195,7 +165,7 @@ def inspect_sound(filepath):
195165

196166
```python
197167
import wave
198-
import sunau
168+
import soundfile as sf
199169
from pathlib import Path
200170

201171
def inspect_sound(filepath):
@@ -219,19 +189,15 @@ def inspect_sound(filepath):
219189
'frames': params.nframes
220190
}
221191

222-
elif suffix == '.au':
223-
with sunau.open(filepath, 'rb') as f:
224-
params = f.getparams()
225-
return {
226-
'format': 'AU',
227-
'channels': params.nchannels,
228-
'sample_width': params.sampwidth,
229-
'sample_rate': params.framerate,
230-
'frames': params.nframes
231-
}
232-
233-
else:
234-
raise ValueError(f"Unsupported format: {suffix}")
192+
# Fallback for other audio formats (including .au, if supported)
193+
info = sf.info(filepath)
194+
return {
195+
'format': info.format,
196+
'channels': info.channels,
197+
'sample_width': None,
198+
'sample_rate': info.samplerate,
199+
'frames': info.frames,
200+
}
235201

236202
# Usage
237203
info = inspect_sound('audio.wav')
@@ -241,7 +207,6 @@ print(f"Sample rate: {info['sample_rate']} Hz")
241207

242208
## Related Modules
243209

244-
- [wave Module](#) - WAV file handling
245-
- [sunau Module](sunau.md) - AU file handling
210+
- [wave Module](wave.md) - WAV file handling
246211
- [aifc Module](aifc.md) - AIFF audio handling
247212
- [struct Module](struct.md) - Binary data parsing

0 commit comments

Comments
 (0)