Skip to content

Conversation

@dbrattli
Copy link
Collaborator

@dbrattli dbrattli commented Dec 14, 2025

  • Improves Python code generation for F# try-with expressions that use typed exception patterns. Instead of generating a single except BaseException with isinstance checks, we now generate separate except clauses for each exception type.
  • Support catching Python BaseException subclasses (KeyboardInterrupt, SystemExit, GeneratorExit) for Python interop

Before:

try:
    run_synchronously(main_async)
except BaseException as match_value:
    if isinstance(match_value, KeyboardInterrupt):
        result = "keyboard"
    elif isinstance(match_value, ArgumentException):
        result = "argument"
    else:
        result = "other"

After:

try:
    run_synchronously(main_async)
except KeyboardInterrupt as match_value:
    result = "keyboard"
except ArgumentException as match_value:
    result = "argument"
except BaseException as match_value:
    result = "other"

@dbrattli dbrattli changed the title Python exception handling [Python] Generate idiomatic except clauses for typed exception patterns Dec 14, 2025
@dbrattli dbrattli merged commit 1b7ce96 into main Dec 14, 2025
22 checks passed
@dbrattli dbrattli deleted the python-exception-handling branch December 14, 2025 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants