Skip to content

Add Python 3.14 support#39

Merged
LanderMoerkerke merged 2 commits into
masterfrom
feature/python314
Apr 29, 2026
Merged

Add Python 3.14 support#39
LanderMoerkerke merged 2 commits into
masterfrom
feature/python314

Conversation

@LanderMoerkerke
Copy link
Copy Markdown
Member

@LanderMoerkerke LanderMoerkerke commented Apr 22, 2026

  • Add support for Python 3.14.

Summary by Sourcery

Add support for running the project and its tests on Python 3.14 by modernizing type inspection and event loop handling.

New Features:

  • Extend CI test matrix to include Python 3.14.

Bug Fixes:

  • Update union type inspection to use typing.get_origin/get_args for compatibility with newer Python versions.
  • Create and manage explicit asyncio event loops in application setup and tests to avoid deprecated get_event_loop behavior.

CI:

  • Expand GitHub Actions workflow matrix to run tests against Python 3.14.

Tests:

  • Adjust test fixtures to use a dedicated asyncio event loop lifecycle compatible with newer Python versions.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

Warning

Rate limit exceeded

@LanderMoerkerke has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 15 minutes and 27 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b483c45a-3d2b-4474-9639-6f773abc53db

📥 Commits

Reviewing files that changed from the base of the PR and between 58119b2 and 52569db.

📒 Files selected for processing (5)
  • .github/workflows/test.yaml
  • natsapi/applications.py
  • natsapi/asyncapi/utils.py
  • tests/asyncapi/test_generation.py
  • tests/fixtures.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/python314

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 15 minutes and 27 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 22, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds Python 3.14 support by modernizing typing usage, making event loop handling explicit and compatible with newer Python versions, and extending CI coverage to Python 3.14.

Sequence diagram for application event loop initialization under Python 3.14

sequenceDiagram
    actor Developer
    participant Application
    participant Asyncio

    Developer->>Application: create_application
    activate Application
    Application->>Asyncio: get_running_loop()
    alt running loop exists
        Asyncio-->>Application: returns existing_loop
        Application->>Application: set loop = existing_loop
        Application->>Application: set _sharing_loop = True
    else no running loop
        Asyncio-->>Application: raises RuntimeError
        Application->>Asyncio: new_event_loop()
        Asyncio-->>Application: returns new_loop
        Application->>Application: set loop = new_loop
        Application->>Application: set _sharing_loop = False
    end
    deactivate Application
    Application-->>Developer: initialized application instance
Loading

File-Level Changes

Change Details Files
Modernize union type inspection to use typing.get_origin/get_args instead of private typing internals for compatibility with newer Python versions.
  • Replace direct isinstance check against typing._UnionGenericAlias with origin check via typing.get_origin
  • Use typing.get_args to extract union parameters when the origin is Union
  • Preserve existing behavior of returning a flat list of response models, falling back to wrapping non-union inputs in a single-element list
natsapi/asyncapi/utils.py
Make event loop fixture create and clean up its own loop to avoid deprecated get_event_loop semantics in newer Python versions.
  • Replace asyncio.get_event_loop usage in the event_loop pytest fixture with asyncio.new_event_loop
  • Ensure the created event loop is yielded to tests and closed after use to avoid resource leaks
tests/fixtures.py
Ensure application event loop initialization does not rely on deprecated asyncio.get_event_loop behavior.
  • Keep preferring asyncio.get_running_loop when available
  • Fall back to creating a new event loop via asyncio.new_event_loop instead of asyncio.get_event_loop when no running loop exists
  • Maintain the _sharing_loop flag to distinguish between shared and internal loops
natsapi/applications.py
Extend CI matrix to test against Python 3.14.
  • Add Python 3.14 to the GitHub Actions test workflow python-version matrix while preserving existing versions and dependency combinations
.github/workflows/test.yaml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@LanderMoerkerke LanderMoerkerke changed the title Add Python 3.14 to test versions Add Python 3.14 support Apr 22, 2026
@LanderMoerkerke LanderMoerkerke marked this pull request as ready for review April 29, 2026 14:04
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • When creating a new event loop in applications.py on RuntimeError, consider setting it as the current loop and ensuring it is eventually closed to avoid leaking loops and to keep behavior closer to the previous get_event_loop() semantics.
  • In the event_loop fixture, you create a new loop but never install it via asyncio.set_event_loop(loop), which may surprise code that relies on get_event_loop() returning the same loop used by tests; consider explicitly setting and restoring the event loop in the fixture.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- When creating a new event loop in `applications.py` on `RuntimeError`, consider setting it as the current loop and ensuring it is eventually closed to avoid leaking loops and to keep behavior closer to the previous `get_event_loop()` semantics.
- In the `event_loop` fixture, you create a new loop but never install it via `asyncio.set_event_loop(loop)`, which may surprise code that relies on `get_event_loop()` returning the same loop used by tests; consider explicitly setting and restoring the event loop in the fixture.

## Individual Comments

### Comment 1
<location path="natsapi/asyncapi/utils.py" line_range="64-65" />
<code_context>
     """
-    if type(r) is typing._UnionGenericAlias:
-        return list(r.__args__)
+    if typing.get_origin(r) is Union:
+        return list(typing.get_args(r))
     else:
         return [r]
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider using `typing.Union` explicitly or comparing to `types.UnionType` for better forward compatibility.

Using bare `Union` relies on it being imported and only matches `typing.Union`, not `|`-style unions (`types.UnionType`). For annotations using `|` (Python 3.10+), `typing.get_origin(r)` returns `types.UnionType`, so the `is Union` check will miss them. Consider something like:

```python
origin = typing.get_origin(r)
if origin in (typing.Union, types.UnionType):
    return list(typing.get_args(r))
```

so both forms are handled.

Suggested implementation:

```python
    :r Single or multiple response models
    """
    origin = typing.get_origin(r)
    if origin in (typing.Union, types.UnionType):
        return list(typing.get_args(r))
    else:
        return [r]

```

1. At the top of `natsapi/asyncapi/utils.py`, ensure `types` is imported, e.g. add `import types` alongside the existing imports.
2. Ensure `typing` is imported as `import typing` (if not already) so `typing.Union`, `typing.get_origin`, and `typing.get_args` are available.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread natsapi/asyncapi/utils.py Outdated
@LanderMoerkerke LanderMoerkerke merged commit 93c4438 into master Apr 29, 2026
11 checks passed
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.

1 participant