Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for Python 3.13 #3850

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open

feat: add support for Python 3.13 #3850

wants to merge 38 commits into from

Conversation

cofin
Copy link
Member

@cofin cofin commented Nov 9, 2024

Description

This PR implements support for Python 3.13.

Note

  • Python 3.8 continues to be supported with the existing msgspec implementation, while all other versions prefer the pre-built litestar wheels.
  • There are no Python 3.13 prebuilt wheels for psycopg[binary]. If you rely on this for development, you'll need to have the postgres development libraries installed
  • picologging does not currently support Python 3.13. These tests are skipped automatically.
  • uses an updated pytest-asyncio. Once the branch has been merged upstream, we can remove this test dependency.
  • Running make install will still install using Python 3.12. This is done to ensure we don't get additional bug reports due to build dependencies missing. If you want to use python 3.13, run uv sync --all-extras --dev --python 3.13

Closes

@github-actions github-actions bot added area/ci This PR involves changes to the CI/Infra area/dependencies This PR involves changes to the dependencies size: small type/feat pr/internal labels Nov 9, 2024
@cofin cofin marked this pull request as ready for review December 15, 2024 17:27
@cofin cofin requested review from a team as code owners December 15, 2024 17:27
@cofin cofin changed the title feat: 3.13 testing feat: add support for Python 3.13 Dec 15, 2024
@github-actions github-actions bot added area/docs This PR involves changes to the documentation area/logging size: medium and removed size: small labels Dec 15, 2024
pyproject.toml Outdated Show resolved Hide resolved
@@ -130,13 +135,14 @@ dev = [
"trio",
"aiosqlite",
"asyncpg>=0.29.0",
"psycopg[pool,binary]>=3.1.10,<3.2",
"psycopg[pool,binary]>=3.1.10,<3.2; python_version < \"3.13\"",
"psycopg[pool,c]; python_version >= \"3.13\"",
Copy link
Member Author

Choose a reason for hiding this comment

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

Package needs to be built for 3.13

tests/helpers.py Outdated Show resolved Hide resolved

exec(f"async def test_fn({reserved_kwarg}: int) -> None: pass")
handler_with_path_param = decorator("/{" + reserved_kwarg + ":int}")(locals()["test_fn"])
local = dict(locals(), **globals())
Copy link
Member Author

Choose a reason for hiding this comment

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

This also caused some weird issues with the scope of the locals() output. This was the only way I could consistently make sure the call to locals contained the test_fn key

pyproject.toml Outdated Show resolved Hide resolved
@cofin
Copy link
Member Author

cofin commented Dec 30, 2024

Breaking off a few smaller PRs that are unrelated but caused errors based on linting and environment updates.

#3918 #3917 #3916

@github-actions github-actions bot added size: small and removed size: medium area/logging area/docs This PR involves changes to the documentation labels Dec 30, 2024
Base automatically changed from psycopg-logging to main January 4, 2025 21:43
Copy link

codecov bot commented Jan 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.34%. Comparing base (2fb6f6b) to head (7eca82e).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3850   +/-   ##
=======================================
  Coverage   98.34%   98.34%           
=======================================
  Files         347      347           
  Lines       15727    15727           
  Branches     1738     1738           
=======================================
  Hits        15467    15467           
  Misses        124      124           
  Partials      136      136           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +106 to +121
if sys.version_info < (3, 13):
with caplog.at_level(logging.INFO):
client = create_test_client(
route_handlers=[post_handler], middleware=[MiddlewareProtocolRequestLoggingMiddleware]
)
response = client.post("/", json={"name": "moishe zuchmir", "age": 40, "programmer": True})
assert response.status_code == 201
assert "test logging" in caplog.text
else:
client = create_test_client(
route_handlers=[post_handler], middleware=[MiddlewareProtocolRequestLoggingMiddleware]
)
response = client.post("/", json={"name": "moishe zuchmir", "age": 40, "programmer": True})
assert response.status_code == 201
assert "test logging" in caplog.text
log = capsys.readouterr()
assert "test logging" in log.err
Copy link
Member Author

Choose a reason for hiding this comment

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

I've tried everything to get these to behave more consistently. For now, this is working, but I think it should be revisited. However, let's not hold up because of this.

@@ -1,5 +1,5 @@
default_language_version:
python: "3"
python: "3.12"
Copy link
Member Author

Choose a reason for hiding this comment

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

We want to leave the version at 3.12 to avoid having to have the odd dependency setup for 3.13. Once psycopg ships with a binary, we can change this to 3.13

pydantic = [
"pydantic",
"email-validator",
"pydantic-extra-types!=2.9.0; python_version < \"3.9\"",
Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like only the 2.9.0 version is impacted. Since it wasn't pulled from pypi, i'm just ignoring this single release.

@cofin
Copy link
Member Author

cofin commented Jan 5, 2025

For reference on the pytest-asyncio issues, please see this PR

pyproject.toml Outdated Show resolved Hide resolved
Copy link

sonarqubecloud bot commented Jan 5, 2025

Copy link

github-actions bot commented Jan 5, 2025

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/3850

Comment on lines +178 to +179
"pytest-asyncio; python_version < \"3.13\"",
"pytest-asyncio @ git+https://github.com/provinzkraut/pytest-asyncio.git@shutdown-asyncgens; python_version >= \"3.13\"",
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
"pytest-asyncio; python_version < \"3.13\"",
"pytest-asyncio @ git+https://github.com/provinzkraut/pytest-asyncio.git@shutdown-asyncgens; python_version >= \"3.13\"",
"pytest-asyncio",

Revert this once the PR has been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ci This PR involves changes to the CI/Infra area/dependencies This PR involves changes to the dependencies pr/internal size: small type/feat
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants