Skip to content

Commit 50e3748

Browse files
heikkitoivonencodex
andcommitted
Docs: Update stdlib docs and add time
Co-Authored-By: Codex <codex@openai.com>
1 parent d7a8d80 commit 50e3748

21 files changed

Lines changed: 176 additions & 133 deletions

DOCUMENTATION_STATUS.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ This document tracks the coverage of built-in functions, types, and standard lib
55
## Overview
66

77
- **Total Items**: 313 (150 builtins + 163 stdlib modules)
8-
- **Documented**: 385 (174 builtins + 211 stdlib)
9-
- **Coverage**: 123.0%
8+
- **Documented**: 386 (174 builtins + 212 stdlib)
9+
- **Coverage**: 123.3%
1010

1111
**Note**: Coverage exceeds 100% because comprehensive documentation files (like `exceptions.md`) cover multiple individual items, and we document deprecated/removed modules for historical reference.
1212

@@ -203,7 +203,7 @@ Complete coverage of all built-in functions, types, exceptions, and constants:
203203

204204
## Standard Library Modules
205205

206-
**Coverage: 129.4% (211/163)**
206+
**Coverage: 130.1% (212/163)**
207207

208208
All standard library modules are fully documented, including new Python 3.14 modules. Coverage exceeds 100% due to documentation of deprecated/removed modules for historical reference.
209209

@@ -312,11 +312,11 @@ All file and I/O modules now documented:
312312
-`shutil` - High-level file operations
313313
-`tempfile` - Temporary files
314314

315-
### ✅ ALL MODULES COMPLETE (211/211)
315+
### ✅ ALL MODULES COMPLETE (212/212)
316316

317317
All 108 previously undocumented stdlib modules have been added:
318318

319-
**Utilities & System (22)**
319+
**Utilities & System (23)**
320320
-`ast` - Abstract syntax trees
321321
-`dis` - Disassembler for bytecode
322322
-`doctest` - Testing via docstrings
@@ -338,6 +338,7 @@ All 108 previously undocumented stdlib modules have been added:
338338
-`stat` - File status constants
339339
-`sysconfig` - System configuration
340340
-`syslog` - System logger
341+
-`time` - Time-related functions
341342
-`trace` - Trace execution
342343

343344
**String & Text Processing (4)**

data/documentation_audit.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@
168168
},
169169
"stdlib": {
170170
"total": 163,
171-
"documented": 211,
172-
"coverage_percent": 129.4,
171+
"documented": 212,
172+
"coverage_percent": 130.1,
173173
"missing": [
174174
"audit_documentation",
175175
"cProfile",
@@ -179,7 +179,7 @@
179179
},
180180
"summary": {
181181
"total_items": 313,
182-
"total_documented": 385,
183-
"overall_coverage_percent": 123.0
182+
"total_documented": 386,
183+
"overall_coverage_percent": 123.3
184184
}
185185
}

docs/stdlib/tabnanny.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ The `tabnanny` module checks Python source files for mixed tabs and spaces in in
66

77
| Operation | Time | Space | Notes |
88
|-----------|------|-------|-------|
9-
| Check file | O(n) | O(n) | n = file lines |
10-
| Verify indent | O(1) | O(1) | Per line |
9+
| Check file/directory | O(n) | O(d) | n = file tokens scanned, d = max indent depth |
1110

1211
## Checking Indentation
1312

@@ -17,11 +16,7 @@ The `tabnanny` module checks Python source files for mixed tabs and spaces in in
1716
import tabnanny
1817

1918
# Check file - O(n)
20-
result = tabnanny.check('myfile.py')
21-
22-
# Returns True if issues found
23-
if result:
24-
print("File has tab/space issues")
19+
tabnanny.check('myfile.py') # Prints diagnostics to stdout; returns None
2520

2621
# Or from command line:
2722
# python -m tabnanny myfile.py

docs/stdlib/tarfile.md

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,33 @@ The `tarfile` module provides tools for working with TAR archives.
66

77
| Operation | Time | Space | Notes |
88
|-----------|------|-------|-------|
9-
| `TarFile.open(name)` | O(n) | O(n) | Open and read directory |
9+
| `TarFile.open(name)` | O(1) | O(1) | Opens archive; no full header scan |
1010
| `TarFile.getmembers()` | O(n) | O(n) | Get all member info, n = file count |
11-
| `TarFile.getmember(name)` | O(n) | O(1) | Linear search through headers |
12-
| `TarFile.extractfile(name)` | O(m) | O(m) | Extract single file, m = size |
13-
| `TarFile.extract(name)` | O(m) | O(m) | Extract to filesystem |
14-
| `TarFile.extractall()` | O(m) | O(m) | Extract all files |
11+
| `TarFile.getmember(name)` | O(n) | O(n) | Loads member list on first call |
12+
| `TarFile.extractfile(name)` | O(n) | O(1) | Returns file object; reading is O(m) |
13+
| `TarFile.extract(name)` | O(n + m) | O(k) | n = members, m = file size, k = buffer |
14+
| `TarFile.extractall()` | O(n + m) | O(n + k) | Member cache for seekable archives |
1515
| `TarFile.add(name)` | O(m) | O(k) | Add file, k = buffer size |
1616

1717
## Opening Archives
1818

19-
### Time Complexity: O(n)
20-
21-
Where n = number of files in archive (reading headers).
19+
### Time Complexity: O(1)
2220

2321
```python
2422
import tarfile
2523

26-
# Opening TAR: O(n) where n = number of files
27-
# Reads all headers sequentially
24+
# Opening TAR: O(1) relative to archive size
25+
# Headers are read lazily when you iterate or call getmembers()
2826
with tarfile.open('archive.tar', 'r') as tar:
29-
# O(n) to process headers
30-
members = tar.getmembers() # O(n)
27+
members = tar.getmembers() # O(n) when called
3128
```
3229

33-
### Space Complexity: O(n)
30+
### Space Complexity: O(1) until you load members
3431

3532
```python
3633
import tarfile
3734

38-
# Memory for member information
35+
# Memory for member information is allocated on getmembers()
3936
with tarfile.open('archive.tar', 'r') as tar:
4037
# Stores info for all files: O(n)
4138
members = tar.getmembers() # O(n) memory
@@ -52,15 +49,16 @@ import tarfile
5249

5350
with tarfile.open('archive.tar', 'r') as tar:
5451
# Finding member: O(n) linear search
55-
# (no index, searches headers sequentially)
52+
# (no index; member list is built by scanning headers)
5653
member = tar.getmember('file.txt') # O(n)
5754

55+
# Getting a file object: O(n)
56+
f = tar.extractfile('file.txt') # O(n)
5857
# Reading file: O(m)
59-
f = tar.extractfile('file.txt') # O(m)
6058
content = f.read() # O(m)
6159
```
6260

63-
### Space Complexity: O(m)
61+
### Space Complexity: O(k) unless you read everything
6462

6563
```python
6664
import tarfile
@@ -113,37 +111,40 @@ with tarfile.open('archive.tar', 'r') as tar:
113111

114112
## Extracting Files
115113

116-
### Time Complexity: O(m)
114+
### Time Complexity: O(n + m)
117115

118116
Where m = total size of extracted files.
119117

120118
```python
121119
import tarfile
122120

123121
with tarfile.open('archive.tar', 'r') as tar:
124-
# Extract single file: O(m)
125-
# m = file size
126-
tar.extract('file.txt') # O(m)
122+
# Extract single file: O(n + m)
123+
# n = header scan (if not loaded), m = file size
124+
tar.extract('file.txt') # O(n + m)
127125

128-
# Extract all: O(sum of sizes)
126+
# Extract all: O(n + sum of sizes)
129127
# Processes each file sequentially
130-
tar.extractall() # O(m) where m = total uncompressed size
128+
tar.extractall() # O(n + m) where m = total uncompressed size
131129

132-
# Extract with path: O(m) + filesystem I/O
133-
tar.extractall(path='output_dir') # O(m)
130+
# Extract with path: O(n + m) + filesystem I/O
131+
tar.extractall(path='output_dir') # O(n + m)
134132
```
135133

136-
### Space Complexity: O(k)
134+
### Space Complexity: O(n + k) for seekable archives
137135

138136
Where k = buffer size during extraction.
139137

140138
```python
141139
import tarfile
142140

143-
# Extraction uses streaming buffers
141+
# Extraction uses streaming buffers; seekable archives cache members
144142
with tarfile.open('archive.tar', 'r') as tar:
145-
tar.extractall() # O(k) space, k = buffer size
146-
# NOT O(m), memory efficient
143+
tar.extractall() # O(n + k) space (member cache + buffers)
144+
145+
# Stream modes avoid member caching
146+
with tarfile.open('archive.tar', 'r|*') as tar:
147+
tar.extractall() # O(k) space
147148
```
148149

149150
## Creating Archives
@@ -219,6 +220,16 @@ with tarfile.open('archive.tar.xz', 'w:xz') as tar:
219220
tar.add('file.txt') # O(m) with highest constant factor
220221
```
221222

223+
### Zstandard Compression (tar.zst)
224+
225+
```python
226+
import tarfile
227+
228+
# Zstandard: fast with tunable compression
229+
with tarfile.open('archive.tar.zst', 'w:zst') as tar:
230+
tar.add('file.txt') # O(m) with compression overhead
231+
```
232+
222233
## Common Patterns
223234

224235
### Iterating Members
@@ -340,6 +351,7 @@ with tarfile.open('archive.tar.xz', 'w:xz') as tar:
340351
- **Python 2.7+**: Enhanced features
341352
- **Python 3.0+**: Improved compression support
342353
- **Python 3.3+**: Support for XZ compression
354+
- **Python 3.14+**: Support for Zstandard compression
343355

344356
## Related Documentation
345357

docs/stdlib/tempfile.md

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@ The `tempfile` module provides utilities for creating and managing temporary fil
66

77
| Operation | Time | Space | Notes |
88
|-----------|------|-------|-------|
9-
| `NamedTemporaryFile()` | O(1) | O(1) initial | Create file; O(n) for data written |
10-
| `TemporaryFile()` | O(1) | O(1) initial | Create file; O(n) for data written |
11-
| `TemporaryDirectory()` | O(1) | O(1) initial | Create dir; O(n) for files created |
12-
| `mktemp()` | O(1) | O(n) | Generate temp name (deprecated) |
13-
| `mkdtemp()` | O(1) | O(n) | Create temp directory safely |
9+
| `NamedTemporaryFile()` | O(r) | O(1) initial | r = name attempts (<= TMP_MAX) |
10+
| `TemporaryFile()` | O(r) | O(1) initial | r = name attempts (<= TMP_MAX) |
11+
| `TemporaryDirectory()` | O(r) | O(1) initial | r = name attempts (<= TMP_MAX) |
12+
| `mktemp()` | O(r) | O(1) | Generate temp name (deprecated) |
13+
| `mkdtemp()` | O(r) | O(1) | Create temp directory safely |
1414
| `gettempdir()` | O(1) | O(1) | Get system temp directory |
1515
| `gettempprefix()` | O(1) | O(1) | Get temp filename prefix |
1616

1717
## Named Temporary Files
1818

1919
### NamedTemporaryFile()
2020

21-
#### Time Complexity: O(1)
21+
#### Time Complexity: O(r)
22+
23+
Where r = number of name attempts (<= TMP_MAX).
2224

2325
```python
2426
import tempfile
@@ -53,20 +55,22 @@ with tempfile.NamedTemporaryFile() as f:
5355

5456
### TemporaryFile()
5557

56-
#### Time Complexity: O(1)
58+
#### Time Complexity: O(r)
59+
60+
Where r = number of name attempts (<= TMP_MAX).
5761

5862
```python
5963
import tempfile
6064

61-
# In-memory file (Unix)
65+
# Unnamed temp file; uses O_TMPFILE when supported, otherwise creates and unlinks
6266
with tempfile.TemporaryFile(mode='w+') as f:
6367
f.write('data')
6468
f.seek(0)
6569
content = f.read() # O(n) read
6670
# Auto-deleted
6771

68-
# File-based fallback (Windows)
69-
# Operation time still O(1) for creation
72+
# File-based fallback (e.g., when O_TMPFILE is unsupported)
73+
# Creation time still O(r) for name attempts
7074
temp = tempfile.TemporaryFile()
7175
temp.write(b'content')
7276
temp.close()
@@ -86,7 +90,9 @@ with tempfile.TemporaryFile() as f:
8690

8791
### TemporaryDirectory()
8892

89-
#### Time Complexity: O(1)
93+
#### Time Complexity: O(r)
94+
95+
Where r = number of name attempts (<= TMP_MAX).
9096

9197
```python
9298
import tempfile
@@ -124,7 +130,9 @@ with tempfile.TemporaryDirectory() as tmpdir:
124130

125131
### mkdtemp()
126132

127-
#### Time Complexity: O(1)
133+
#### Time Complexity: O(r)
134+
135+
Where r = number of name attempts (<= TMP_MAX).
128136

129137
```python
130138
import tempfile
@@ -140,13 +148,13 @@ tmpdir = tempfile.mkdtemp(prefix='myapp_')
140148
tmpdir = tempfile.mkdtemp(suffix='_backup')
141149
```
142150

143-
#### Space Complexity: O(n)
151+
#### Space Complexity: O(1)
144152

145153
```python
146154
import tempfile
147155

148156
# Directory name stored
149-
tmpdir = tempfile.mkdtemp() # O(n) for path string
157+
tmpdir = tempfile.mkdtemp() # O(1) extra memory
150158
```
151159

152160
### gettempdir()
@@ -295,11 +303,6 @@ else: # Unix/Linux
295303
tmpdir = tempfile.mkdtemp(dir='/custom/path')
296304
```
297305

298-
## Version Notes
299-
300-
- **Python 3.10+**: Improved cleanup with weak references
301-
- **Python 3.12+**: Enhanced security defaults
302-
303306
## Related Documentation
304307

305308
- [Pathlib Module](pathlib.md) - Object-oriented filesystem paths

docs/stdlib/termios.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ try:
3232
new_settings
3333
)
3434

35-
# Now stdin is in raw mode
35+
# Now stdin is in non-canonical mode (not full raw mode)
3636
ch = sys.stdin.read(1)
3737
print(f"Got: {repr(ch)}")
3838

docs/stdlib/textwrap.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,13 @@ filled = fill(text, width=80) # O(n) once
273273
```python
274274
from textwrap import wrap
275275

276-
# For very large text, generator approach
277-
def wrap_large_text(text, width=80):
278-
"""Wrap large text efficiently."""
279-
for line in wrap(text, width=width): # O(n)
280-
yield line # Lazy evaluation
281-
282-
# Process one line at a time
283-
for wrapped_line in wrap_large_text(huge_text):
284-
process(wrapped_line)
276+
# wrap() returns a list, so it still holds all lines in memory
277+
lines = wrap(huge_text, width=80) # O(n) memory
278+
279+
# For large inputs, wrap per paragraph to limit peak memory
280+
for paragraph in huge_text.split("\n\n"):
281+
for line in wrap(paragraph, width=80):
282+
process(line)
285283
```
286284

287285
## TextWrapper Class

docs/stdlib/this.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ The `this` module displays the Zen of Python, a philosophy guide for Python prog
66

77
| Operation | Time | Space | Notes |
88
|-----------|------|-------|-------|
9-
| Import module | O(1) | O(1) | Decodes and prints Zen text |
9+
| Import module | O(n) | O(n) | n = Zen text length (decode + print) |
1010

1111
## The Zen of Python
1212

1313
### Viewing the Zen
1414

1515
```python
16-
import this
16+
import this # Prints on import
1717

1818
# Prints:
1919
# The Zen of Python, by Tim Peters

0 commit comments

Comments
 (0)