PR #117860
tensorflow/tensorflow · Python API · Merged · 4 files changed
Standardized exception handling across 4 modules in tensorflow/python by replacing generic Exception catches with targeted exception classes, ensuring type errors and internal invariant failures are never masked.
Checkout Pull Request
Inspect the full commit history and diff locally from upstream tensorflow/tensorflow.
$gh pr checkout 117860 --repo tensorflow/tensorflowStandardized exception handling across 4 modules in tensorflow/python by replacing generic Exception catches with targeted exception classes, ensuring type errors and internal invariant failures are never masked.
File-by-File Modification Breakdown (4)
- +2 / -4
tensorflow/python/ops/numpy_ops/tests/config.py
Python/XLA regression test suite verifying edge-case behavior
- +1 / -1
tensorflow/python/platform/benchmark.py
Upstream Python/C++ module implementation
- +1 / -1
tensorflow/python/tools/selective_registration_header_lib.py
Upstream Python/C++ module implementation
- +13 / -9
tensorflow/python/tpu/client/client.py
Upstream Python/C++ module implementation
Changed Files (4)
1. Introduction & Motivation
Core Python test and configuration utilities under tensorflow/python contained broad except Exception: blocks that violated TensorFlow's static analysis guidelines and hindered debugging by swallowing unexpected runtime failures [1].
2. Fault-Isolation Invariant & Code Example
By restricting exception handlers to the exact failure modes a helper expects (such as OSError, KeyError, or ValueError), unrelated internal errors surface immediately during CI:
3. References
- Google Python Style Guide, Exceptions & Error-Handling Contracts.