Skip to content

Commit 892bb05

Browse files
gpsheadclaude
andcommitted
Update control flow exception handling to acknowledge configurability need
Based on feedback from @picnixz about Sphinx's Skip exception and other projects using exceptions for control flow: 1. Renamed "Special Cases" to "Control Flow Exceptions" for clarity 2. Added acknowledgment that other projects need this configurability 3. Deferred specific API design to open issues 4. Updated Open Issue #5 with key challenges: - API design options (env var vs Python API) - Performance constraints in the hot path - Subclass handling complexity - Whether to expand the default exclusion list The PEP now acknowledges the need for configurability while leaving the specific implementation approach as an open question requiring careful API design and performance testing. 🤖 Generated with Claude Code (https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 47d0b78 commit 892bb05

1 file changed

Lines changed: 25 additions & 13 deletions

File tree

peps/pep-08XX.rst

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -241,17 +241,21 @@ class. This attribute will store the time in nanoseconds since the Unix epoch
241241
- The timestamp represents when the exception object was created, which is
242242
typically when it was raised
243243

244-
Special Cases
245-
-------------
244+
Control Flow Exceptions
245+
------------------------
246246

247247
To avoid performance impacts on normal control flow, timestamps will **not** be
248-
collected for the following exception types even when the feature is enabled:
248+
collected for certain exception types even when the feature is enabled. By default:
249249

250250
- ``StopIteration``
251251
- ``AsyncStopIteration``
252252

253253
These exceptions are frequently used for control flow in iterators and async
254-
iterators, and adding timestamps would introduce unnecessary overhead.
254+
iterators. However, other projects also use custom exceptions for control flow
255+
(e.g., Sphinx's ``Skip`` exception), making the need for configurability clear.
256+
257+
The current implementation hard-codes these two exceptions for performance
258+
reasons. See Open Issues for discussion about making this configurable.
255259

256260
Configuration
257261
-------------
@@ -436,15 +440,23 @@ Open Issues
436440

437441
5. **Control flow exception handling**: The current implementation does not collect
438442
timestamps for ``StopIteration`` and ``AsyncStopIteration`` to avoid performance
439-
impact on normal control flow. Several questions arise:
440-
441-
- Should this exclusion be configurable at runtime?
442-
- Should it apply to subclasses of these exceptions?
443-
- The check for these specific exceptions is in the hot path of exception
444-
creation and must be extremely fast. The current implementation uses a simple
445-
type check for performance. Adding complexity like subclass checks or a
446-
configurable tuple of excluded exceptions would impact performance. Is the
447-
current simple approach acceptable?
443+
impact on normal control flow. However, other projects use custom exceptions for
444+
control flow (e.g., Sphinx's ``Skip`` exception), requiring configurability.
445+
446+
Key challenges:
447+
448+
- **API Design**: What's the best way to allow projects to register their
449+
control-flow exceptions? Environment variable? Python API? Both?
450+
- **Performance**: The check is in the hot path of exception creation and must
451+
be extremely fast. How can we make this configurable without impacting
452+
performance for the common case?
453+
- **Subclass handling**: Should exclusions apply to subclasses? This adds
454+
complexity and performance overhead.
455+
- **Default set**: Should we expand the default exclusion list beyond
456+
``StopIteration`` and ``AsyncStopIteration``?
457+
458+
This needs careful API design and performance testing before committing to
459+
a specific approach.
448460

449461

450462
Acknowledgements

0 commit comments

Comments
 (0)