Skip to content

Conversation

@Robbie-Palmer
Copy link
Contributor

Summary

Replace bare except: blocks with specific exception tuple except (TypeError, ValueError, AttributeError, KeyError): in the union property parsing template.

Changes

  • Updated openapi_python_client/templates/property_templates/union_property.py.jinja:24 to catch only specific exceptions relevant to parsing operations
  • Removed # noqa: E722 linting suppression comments that are no longer needed
  • Regenerated all golden records to reflect template changes

Benefits

  • Makes error handling more explicit and intentional
  • Avoids catching system exceptions like KeyboardInterrupt or SystemExit
  • Improves code quality and complies with PEP 8 style guidelines
  • Removes the need for linting suppressions

Test plan

  • Regenerated golden records with pdm regen
  • Verified all generated model files with union properties now use specific exception handling
  • Confirmed the exception tuple covers the relevant error cases for parsing (TypeError, ValueError, AttributeError, KeyError)

Replace bare `except:` with specific exception tuple `except (TypeError, ValueError, AttributeError, KeyError):` in union property parsing template. This improves code quality by:

- Making error handling more explicit and intentional
- Avoiding catching system exceptions like KeyboardInterrupt or SystemExit
- Removing the need for noqa: E722 linting suppressions
- Making the code comply with PEP 8 style guidelines

All generated models with union properties now use specific exception handling in their _parse functions.
@Robbie-Palmer Robbie-Palmer force-pushed the fix/bare-except-blocks branch from b5e43a7 to 63fbbff Compare October 31, 2025 16:04
Copy link
Collaborator

@dbanty dbanty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely, thanks!

@dbanty dbanty added this pull request to the merge queue Oct 31, 2025
Merged via the queue into openapi-generators:main with commit 72e4efe Oct 31, 2025
22 checks passed
@knope-bot knope-bot bot mentioned this pull request Oct 31, 2025
@Robbie-Palmer Robbie-Palmer deleted the fix/bare-except-blocks branch October 31, 2025 16:20
github-merge-queue bot pushed a commit that referenced this pull request Nov 3, 2025
> [!IMPORTANT]
> Merging this pull request will create this release

## Fixes

- Remove non-existent CHANGELOG.md references from UV and Poetry
templates (#1344)
- Initialize optional lists as UNSET, not [] (#1346)
- Correct docstring typos in client template (#1347)
- Replace bare except blocks with specific exception types (#1348)

### Update `uv_build` to 0.9

#1352 by @johnthagen

`uv` has been in the `0.9.x` release cycle for a while, so update
templates to use the corresponding `uv_build` range.

Co-authored-by: knope-bot[bot] <152252888+knope-bot[bot]@users.noreply.github.com>
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