Skip to content

Commit 166c5f6

Browse files
heikkitoivonencodex
andcommitted
Docs: Add resource/grp/xml docs and fix stdlib complexities
Co-Authored-By: Codex <codex@openai.com>
1 parent 975da22 commit 166c5f6

14 files changed

Lines changed: 325 additions & 55 deletions

DOCUMENTATION_STATUS.md

Lines changed: 12 additions & 7 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**: 317 (150 builtins + 167 stdlib modules)
8-
- **Documented**: 382 (174 builtins + 208 stdlib)
9-
- **Coverage**: 120.5%
8+
- **Documented**: 387 (174 builtins + 213 stdlib)
9+
- **Coverage**: 122.1%
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: 124.6% (208/167)**
206+
**Coverage: 127.5% (213/167)**
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

@@ -305,9 +305,9 @@ All file and I/O modules now documented:
305305
-`shutil` - High-level file operations
306306
-`tempfile` - Temporary files
307307

308-
### ✅ ALL MODULES COMPLETE (208/208)
308+
### ✅ ALL MODULES COMPLETE (213/213)
309309

310-
All 105 previously undocumented stdlib modules have been added:
310+
All 110 previously undocumented stdlib modules have been added:
311311

312312
**Utilities & System (20)**
313313
-`ast` - Abstract syntax trees
@@ -416,19 +416,24 @@ All 105 previously undocumented stdlib modules have been added:
416416
-`this` - Zen of Python
417417
-`readline` - Line-editing support
418418

419-
**System & Locale (5)**
419+
**System & Locale (7)**
420420
-`netrc` - Netrc file handling
421421
-`site` - Site-specific configuration
422422
-`crypt` - Password hashing (Unix)
423423
-`fcntl` - File control (Unix)
424424
-`termios` - POSIX terminal I/O control
425+
-`resource` - Process resource limits (Unix)
426+
-`grp` - Unix group database
425427

426-
**Internal & Testing (5)**
428+
**Internal & Testing (11)**
427429
-`concurrent` - Concurrency (parent package)
428430
-`copyreg` - Copy registration
429431
-`encodings` - Built-in encodings
430432
-`xdrlib` - XDR serialization
431433
-`xml` - XML parsing base
434+
-`xml.dom` - DOM XML APIs
435+
-`xml.sax` - SAX XML APIs
436+
-`xml.etree.ElementTree` - ElementTree XML APIs
432437
-`binascii` - Binary-ASCII conversion
433438
-`marshal` - Object serialization
434439
-`webbrowser` - Browser control

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": 167,
171-
"documented": 208,
172-
"coverage_percent": 124.6,
171+
"documented": 213,
172+
"coverage_percent": 127.5,
173173
"missing": [
174174
"audit_documentation",
175175
"cProfile",
@@ -179,7 +179,7 @@
179179
},
180180
"summary": {
181181
"total_items": 317,
182-
"total_documented": 382,
183-
"overall_coverage_percent": 120.5
182+
"total_documented": 387,
183+
"overall_coverage_percent": 122.1
184184
}
185185
}

docs/stdlib/grp.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# grp Module
2+
3+
The `grp` module provides access to the Unix group database (e.g., `/etc/group`). It is Unix-only.
4+
5+
!!! warning "Unix-only"
6+
The `grp` module is not available on Windows and may not be available on some Python builds.
7+
8+
## Complexity Reference
9+
10+
| Operation | Time | Space | Notes |
11+
|-----------|------|-------|-------|
12+
| `grp.getgrnam(name)` | O(n) | O(1) | Linear scan of group database in many implementations |
13+
| `grp.getgrgid(gid)` | O(n) | O(1) | Linear scan of group database in many implementations |
14+
| `grp.getgrall()` | O(n) | O(n) | Reads all group entries |
15+
16+
## Common Operations
17+
18+
### Lookup a Group by Name
19+
20+
```python
21+
import grp
22+
23+
# Lookup group by name - O(n)
24+
group = grp.getgrnam('staff')
25+
print(group.gr_name, group.gr_gid)
26+
```
27+
28+
### Lookup a Group by GID
29+
30+
```python
31+
import grp
32+
33+
# Lookup group by id - O(n)
34+
group = grp.getgrgid(20)
35+
print(group.gr_name, group.gr_mem)
36+
```
37+
38+
### List All Groups
39+
40+
```python
41+
import grp
42+
43+
# List all groups - O(n)
44+
for entry in grp.getgrall():
45+
print(entry.gr_name)
46+
```
47+
48+
## Related Modules
49+
50+
- [pwd Module](pwd.md) - Unix password database
51+
- [os Module](os.md) - Process and user information

docs/stdlib/queue.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# queue - Synchronized Queue Data Structures
22

3-
The `queue` module provides thread-safe queue implementations for coordinating work between multiple producer and consumer threads or processes.
3+
The `queue` module provides thread-safe queue implementations for coordinating work between multiple producer and consumer threads.
44

55
## Complexity Reference
66

@@ -10,11 +10,13 @@ The `queue` module provides thread-safe queue implementations for coordinating w
1010
| `Queue.get()` | O(1) | O(1) | Remove item (blocks if empty) |
1111
| `Queue.put_nowait()` | O(1) | O(1) | Add item (raises Full if full) |
1212
| `Queue.get_nowait()` | O(1) | O(1) | Remove item (raises Empty if empty) |
13-
| `Queue.qsize()` | O(1) | O(1) | Get approximate size |
14-
| `PriorityQueue.put()` | O(log n) | O(1) | Add with priority |
15-
| `PriorityQueue.get()` | O(log n) | O(1) | Get highest priority |
13+
| `Queue.qsize()` | O(1) | O(1) | Approximate size (not reliable under contention) |
14+
| `PriorityQueue.put()` | O(log n) | O(1) amortized | Add with priority (heap push) |
15+
| `PriorityQueue.get()` | O(log n) | O(1) amortized | Remove smallest-priority item (heap pop) |
1616
| `LifoQueue.put()` | O(1) amortized | O(1) | Add item (LIFO); uses list internally |
1717
| `LifoQueue.get()` | O(1) | O(1) | Remove item (LIFO) |
18+
| `SimpleQueue.put()` | O(1) | O(1) | Add item (unbounded, never blocks on size) |
19+
| `SimpleQueue.get()` | O(1) | O(1) | Remove item (blocks if empty) |
1820

1921
## Basic Queue (FIFO)
2022

@@ -86,7 +88,6 @@ print("All tasks complete")
8688

8789
```python
8890
from queue import PriorityQueue
89-
import heapq
9091

9192
# Create priority queue - O(1)
9293
pq = PriorityQueue()

docs/stdlib/random.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ The `random` module provides pseudo-random number generation for various probabi
99
| `random.random()` | O(1) | O(1) | Uniform [0.0, 1.0) |
1010
| `random.randint(a, b)` | O(1) | O(1) | Uniform integer |
1111
| `random.choice(seq)` | O(1) | O(1) | Random element |
12-
| `random.choices(seq, k)` | O(k) | O(k) | k items with replacement |
13-
| `random.sample(seq, k)` | O(k) typical, O(n) worst | O(k) | k items without replacement; O(n) when k is close to n |
12+
| `random.choices(seq, k)` | O(k) to O(n + k log n) | O(k) to O(n + k) | O(k) if no weights; builds cumulative weights if provided |
13+
| `random.sample(seq, k)` | O(k) to O(n) | O(k) to O(n) | Copies population when k is large or input is set/dict |
1414
| `random.shuffle(list)` | O(n) | O(1) | In-place Fisher-Yates shuffle |
1515
| `random.uniform(a, b)` | O(1) | O(1) | Uniform float |
1616
| `random.gauss(mu, sigma)` | O(1) | O(1) | Gaussian distribution |
17-
| `random.seed(a)` | O(1) | O(1) | Set seed |
17+
| `random.seed(a)` | O(len(a)) | O(1) | Seed processing depends on input type |
1818

1919
## Basic Random Number Generation
2020

@@ -79,13 +79,13 @@ import random
7979
lst = [1, 2, 3, 4, 5]
8080
selections = random.choices(lst, k=3) # [5, 2, 5] - O(3)
8181

82-
# Weighted selection - O(k)
82+
# Weighted selection - O(n + k log n)
8383
colors = ['red', 'blue', 'green']
8484
weights = [0.5, 0.3, 0.2]
85-
draws = random.choices(colors, weights=weights, k=100) # O(100)
85+
draws = random.choices(colors, weights=weights, k=100) # O(n + k log n)
8686

87-
# Without replacement (sample) - O(k)
88-
unique = random.sample(lst, k=3) # [3, 1, 4] - O(3), no duplicates
87+
# Without replacement (sample) - O(k) to O(n)
88+
unique = random.sample(lst, k=3) # [3, 1, 4] - no duplicates
8989
```
9090

9191
### Shuffling
@@ -188,7 +188,7 @@ def random_partition(arr, low, high):
188188
pivot_idx = random.randint(low, high) # O(1)
189189
# ... partition logic
190190

191-
# Shuffle-sort (random sort for testing) - O(n log n) expected
191+
# Shuffle-sort (bogosort) - expected O(n!) time
192192
def shuffle_sort(arr):
193193
while not is_sorted(arr):
194194
random.shuffle(arr) # O(n) per iteration
@@ -277,7 +277,7 @@ np.random.shuffle(big_arr) # O(1000000)
277277
import random
278278
from bisect import bisect
279279

280-
# Simple weighted choice with normalization - O(1)
280+
# Simple weighted choice with normalization - O(n)
281281
def weighted_choice(choices, weights):
282282
total = sum(weights)
283283
r = random.uniform(0, total)
@@ -288,11 +288,11 @@ def weighted_choice(choices, weights):
288288
upto += weight
289289
return choices[-1]
290290

291-
# O(k) where k = number of choices
292-
# Better: use random.choices() - O(k) but optimized in C
291+
# O(n) where n = number of choices
292+
# Better: use random.choices() when you want multiple draws
293293
items = ['a', 'b', 'c']
294294
weights = [0.5, 0.3, 0.2]
295-
result = random.choices(items, weights=weights, k=1)[0] # O(1)
295+
result = random.choices(items, weights=weights, k=1)[0] # O(n)
296296
```
297297

298298
## State Management
@@ -357,8 +357,8 @@ array = np.random.random(1000) # Fast bulk generation
357357
import random
358358
import threading
359359

360-
# Random module is NOT thread-safe
361-
# Each thread should have its own Random instance
360+
# The module-level RNG is safe to call from multiple threads, but it shares state.
361+
# Use a per-thread Random instance to avoid contention and interleaved sequences.
362362

363363
def worker(seed):
364364
rng = random.Random(seed) # O(1) - thread-safe
@@ -376,8 +376,7 @@ threads = [
376376

377377
- **Python 2.x and 3.x**: Core functions available in all versions
378378
- **Python 3.6+**: `random.choices()` added
379-
- **Python 3.9+**: Algorithm improvements for better quality randomness
380-
- **Different platforms**: May have slight variations in random sequence
379+
- **Different versions**: Some algorithms (e.g., `randrange`) have changed for quality, so sequences may differ
381380

382381
## Related Modules
383382

docs/stdlib/re.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,29 @@ The `re` module provides regular expression matching operations.
77
| Operation | Time | Space | Notes |
88
|-----------|------|-------|-------|
99
| `re.compile(pattern)` | O(n) | O(n) | n = pattern length |
10-
| `pattern.match(string)` | O(m) typical, O(n*m) worst | O(m) | Worst case with backtracking |
11-
| `pattern.fullmatch(string)` | O(m) typical, O(n*m) worst | O(m) | Match entire string |
12-
| `pattern.search(string)` | O(m) typical, O(n*m) worst | O(m) | Searches full string |
13-
| `pattern.findall(string)` | O(n*m) | O(k) | k = number of matches |
14-
| `pattern.finditer(string)` | O(n) per match | O(1) per match | Lazy iteration |
15-
| `pattern.sub(repl, string)` | O(n*m) | O(m) | n = pattern, m = string |
16-
| `pattern.subn(repl, string)` | O(n*m) | O(m) | Like sub, returns (newstr, count) |
17-
| `pattern.split(string)` | O(n*m) | O(m) | n = pattern, m = string |
18-
| `re.match(pattern, string)` | O(n + m) typical | O(m) | Compiles + matches; cached up to ~512; O(n*m) worst with backtracking |
19-
| `re.search(pattern, string)` | O(n + m) typical | O(m) | Compiles + matches; cached up to ~512; O(n*m) worst with backtracking |
10+
| `pattern.match(string)` | O(m) typical, O(exp) worst | O(m) | Worst case from backtracking |
11+
| `pattern.fullmatch(string)` | O(m) typical, O(exp) worst | O(m) | Match entire string |
12+
| `pattern.search(string)` | O(m) typical, O(exp) worst | O(m) | Searches full string |
13+
| `pattern.findall(string)` | O(m) typical, O(exp) worst | O(k) | k = total matches |
14+
| `pattern.finditer(string)` | O(m) typical, O(exp) worst | O(1) | Lazy iteration |
15+
| `pattern.sub(repl, string)` | O(m) typical, O(exp) worst | O(m) | Match + build output |
16+
| `pattern.subn(repl, string)` | O(m) typical, O(exp) worst | O(m) | Like sub, returns (newstr, count) |
17+
| `pattern.split(string)` | O(m) typical, O(exp) worst | O(m) | Split by pattern |
18+
| `re.match(pattern, string)` | O(n + m) typical, O(exp) worst | O(m) | Compiles on cache miss; cached up to ~512 |
19+
| `re.search(pattern, string)` | O(n + m) typical, O(exp) worst | O(m) | Compiles on cache miss; cached up to ~512 |
2020
| `re.escape(string)` | O(n) | O(n) | Escape special regex characters |
21-
| `re.purge()` | O(1) | O(1) | Clear compiled pattern cache |
22-
| `re.error` | - | - | Exception for invalid patterns (alias: PatternError in 3.13+) |
21+
| `re.purge()` | O(c) | O(1) | Clear compiled pattern cache (c = cache size) |
22+
| `re.error` | - | - | Exception for invalid patterns |
2323

24-
*Note: Worst case for catastrophic backtracking; typical cases are much better.
24+
*Note: "O(exp)" denotes exponential time in m from catastrophic backtracking; typical cases are much better.
2525

2626
## Pattern Caching
2727

2828
| Operation | Time | Space | Notes |
2929
|-----------|------|-------|-------|
30-
| `re.match(pattern, s)` | O(n + m) | O(n+m) | Pattern compiled, cached up to ~512 |
30+
| `re.match(pattern, s)` | O(n + m) | O(n+m) | Compiles on cache miss; cached up to ~512 |
3131
| `compiled = re.compile(p)` | O(n) | O(n) | Explicit compilation |
32-
| `compiled.match(s)` | O(n*m)* | O(m) | Uses cached pattern |
32+
| `compiled.match(s)` | O(m) typical, O(exp) worst | O(m) | Uses the already-compiled pattern |
3333

3434
CPython caches the last ~512 compiled patterns automatically.
3535

@@ -178,7 +178,7 @@ print(f"Time: {end - start}s") # Fast!
178178
```python
179179
import re
180180

181-
# Bad: recompiles pattern each time - O(n²)
181+
# Bad: recompiles pattern each time
182182
for line in large_file:
183183
if re.search(r'\d+', line): # Recompiles each time!
184184
process(line)
@@ -254,7 +254,7 @@ match = pattern.search(text) # O(m)
254254

255255
## Version Notes
256256

257-
- **Python 3.7+**: `regex` module available as alternative
257+
- **Third-party**: The `regex` package provides additional features
258258
- **Python 3.x**: `re` module is standard
259259
- **Python 2.x**: Similar but with different Unicode handling
260260

docs/stdlib/reprlib.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ The `reprlib` module provides an alternative repr() implementation that produces
66

77
| Operation | Time | Space | Notes |
88
|-----------|------|-------|-------|
9-
| `repr()` | O(n) | O(n) | n = visible characters |
10-
| Truncation | O(1) | O(1) | Configurable limit |
9+
| `repr()` | O(k) | O(k) | k = items/chars visited up to limits |
10+
| Truncation | O(k) | O(1) | Limit reduces traversal/output, not O(1) |
1111

1212
## Creating Readable Representations
1313

0 commit comments

Comments
 (0)