paper-dynasty-card-creation/batters
Cal Corum db2d81a6d1 CLAUDE: Add default OPS constants and type hints to improve code clarity
This commit adds default OPS value constants and type hints to key functions,
improving code documentation and IDE support.

## Changes Made

1. **Add default OPS constants** (creation_helpers.py)
   - DEFAULT_BATTER_OPS: Default OPS by rarity (1-5)
   - DEFAULT_STARTER_OPS: Default OPS-against for starters (99, 1-5)
   - DEFAULT_RELIEVER_OPS: Default OPS-against for relievers (99, 1-5)
   - Comprehensive comments explaining usage
   - Single source of truth for fallback values

2. **Update batters/creation.py**
   - Import DEFAULT_BATTER_OPS
   - Replace 6 hardcoded if-checks with clean loop over constants
   - Add type hints to post_player_updates function
   - Import Dict from typing

3. **Update pitchers/creation.py**
   - Import DEFAULT_STARTER_OPS and DEFAULT_RELIEVER_OPS
   - Replace 12 hardcoded if-checks with clean loops over constants
   - Add type hints to post_player_updates function
   - Import Dict from typing

4. **Add typing import** (creation_helpers.py)
   - Import Dict, List, Tuple, Optional for type hints
   - Enables type hints throughout helper functions

## Impact

### Before
```python
# Scattered hardcoded values (batters)
if 1 not in average_ops:
    average_ops[1] = 1.066
if 2 not in average_ops:
    average_ops[2] = 0.938
# ... 4 more if-checks

# Scattered hardcoded values (pitchers)
if 99 not in sp_average_ops:
    sp_average_ops[99] = 0.388
# ... 5 more if-checks for starters
# ... 6 more if-checks for relievers
```

### After
```python
# Clean, data-driven approach (batters)
for rarity, default_ops in DEFAULT_BATTER_OPS.items():
    if rarity not in average_ops:
        average_ops[rarity] = default_ops

# Clean, data-driven approach (pitchers)
for rarity, default_ops in DEFAULT_STARTER_OPS.items():
    if rarity not in sp_average_ops:
        sp_average_ops[rarity] = default_ops

for rarity, default_ops in DEFAULT_RELIEVER_OPS.items():
    if rarity not in rp_average_ops:
        rp_average_ops[rarity] = default_ops
```

### Benefits
 Eliminates 18 if-checks across batters and pitchers
 Single source of truth for default OPS values
 Easy to modify values (change constant, not scattered code)
 Self-documenting with clear constant names and comments
 Type hints improve IDE support and catch errors early
 Function signatures now document expected types
 Consistent with other recent refactorings

## Test Results
 42/42 tests pass
 All existing functionality preserved
 100% backward compatible

## Files Modified
- creation_helpers.py: +35 lines (3 constants + typing import)
- batters/creation.py: -4 lines net (cleaner code + type hints)
- pitchers/creation.py: -8 lines net (cleaner code + type hints)

**Net change:** More constants, less scattered magic numbers, better types.

Part of ongoing refactoring to reduce code fragility.
2025-10-31 23:28:49 -05:00
..
__init__.py Refactor pit/bat/def to modules 2023-11-05 12:18:42 -06:00
calcs_batter.py Migrate to rotating file logger 2024-11-10 14:42:12 -06:00
creation.py CLAUDE: Add default OPS constants and type hints to improve code clarity 2025-10-31 23:28:49 -05:00
stat_prep.py December 22 Update 2024-12-22 15:46:52 -06:00