Skip to content

Commit 7ea55e3

Browse files
release: 1.18.1 (#67)
* chore(package): drop Python 3.8 support * fix: compat with Python 3.14 * release: 1.18.1 --------- Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com>
1 parent 40e23bf commit 7ea55e3

File tree

8 files changed

+35
-46
lines changed

8 files changed

+35
-46
lines changed

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "1.18.0"
2+
".": "1.18.1"
33
}

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## 1.18.1 (2025-11-10)
4+
5+
Full Changelog: [v1.18.0...v1.18.1](https://github.com/knocklabs/knock-python/compare/v1.18.0...v1.18.1)
6+
7+
### Bug Fixes
8+
9+
* compat with Python 3.14 ([372ebe8](https://github.com/knocklabs/knock-python/commit/372ebe855b40704df70a619d9db7855702c4e0fd))
10+
11+
12+
### Chores
13+
14+
* **package:** drop Python 3.8 support ([57e0a18](https://github.com/knocklabs/knock-python/commit/57e0a18cc17b86273535c917669dc48fc322a3e3))
15+
316
## 1.18.0 (2025-11-07)
417

518
Full Changelog: [v1.17.0...v1.18.0](https://github.com/knocklabs/knock-python/compare/v1.17.0...v1.18.0)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<!-- prettier-ignore -->
44
[![PyPI version](https://img.shields.io/pypi/v/knockapi.svg?label=pypi%20(stable))](https://pypi.org/project/knockapi/)
55

6-
The Knock Python library provides convenient access to the Knock REST API from any Python 3.8+
6+
The Knock Python library provides convenient access to the Knock REST API from any Python 3.9+
77
application. The library includes type definitions for all request params and response fields,
88
and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).
99

@@ -457,7 +457,7 @@ print(knockapi.__version__)
457457

458458
## Requirements
459459

460-
Python 3.8 or higher.
460+
Python 3.9 or higher.
461461

462462
## Contributing
463463

pyproject.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "knockapi"
3-
version = "1.18.0"
3+
version = "1.18.1"
44
description = "The official Python library for the knock API"
55
dynamic = ["readme"]
66
license = "Apache-2.0"
@@ -15,11 +15,10 @@ dependencies = [
1515
"distro>=1.7.0, <2",
1616
"sniffio",
1717
]
18-
requires-python = ">= 3.8"
18+
requires-python = ">= 3.9"
1919
classifiers = [
2020
"Typing :: Typed",
2121
"Intended Audience :: Developers",
22-
"Programming Language :: Python :: 3.8",
2322
"Programming Language :: Python :: 3.9",
2423
"Programming Language :: Python :: 3.10",
2524
"Programming Language :: Python :: 3.11",
@@ -141,7 +140,7 @@ filterwarnings = [
141140
# there are a couple of flags that are still disabled by
142141
# default in strict mode as they are experimental and niche.
143142
typeCheckingMode = "strict"
144-
pythonVersion = "3.8"
143+
pythonVersion = "3.9"
145144

146145
exclude = [
147146
"_dev",

src/knockapi/_models.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import inspect
5+
import weakref
56
from typing import TYPE_CHECKING, Any, Type, Union, Generic, TypeVar, Callable, Optional, cast
67
from datetime import date, datetime
78
from typing_extensions import (
@@ -573,6 +574,9 @@ class CachedDiscriminatorType(Protocol):
573574
__discriminator__: DiscriminatorDetails
574575

575576

577+
DISCRIMINATOR_CACHE: weakref.WeakKeyDictionary[type, DiscriminatorDetails] = weakref.WeakKeyDictionary()
578+
579+
576580
class DiscriminatorDetails:
577581
field_name: str
578582
"""The name of the discriminator field in the variant class, e.g.
@@ -615,8 +619,9 @@ def __init__(
615619

616620

617621
def _build_discriminated_union_meta(*, union: type, meta_annotations: tuple[Any, ...]) -> DiscriminatorDetails | None:
618-
if isinstance(union, CachedDiscriminatorType):
619-
return union.__discriminator__
622+
cached = DISCRIMINATOR_CACHE.get(union)
623+
if cached is not None:
624+
return cached
620625

621626
discriminator_field_name: str | None = None
622627

@@ -669,7 +674,7 @@ def _build_discriminated_union_meta(*, union: type, meta_annotations: tuple[Any,
669674
discriminator_field=discriminator_field_name,
670675
discriminator_alias=discriminator_alias,
671676
)
672-
cast(CachedDiscriminatorType, union).__discriminator__ = details
677+
DISCRIMINATOR_CACHE.setdefault(union, details)
673678
return details
674679

675680

src/knockapi/_utils/_sync.py

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
from __future__ import annotations
22

3-
import sys
43
import asyncio
54
import functools
6-
import contextvars
7-
from typing import Any, TypeVar, Callable, Awaitable
5+
from typing import TypeVar, Callable, Awaitable
86
from typing_extensions import ParamSpec
97

108
import anyio
@@ -15,34 +13,11 @@
1513
T_ParamSpec = ParamSpec("T_ParamSpec")
1614

1715

18-
if sys.version_info >= (3, 9):
19-
_asyncio_to_thread = asyncio.to_thread
20-
else:
21-
# backport of https://docs.python.org/3/library/asyncio-task.html#asyncio.to_thread
22-
# for Python 3.8 support
23-
async def _asyncio_to_thread(
24-
func: Callable[T_ParamSpec, T_Retval], /, *args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs
25-
) -> Any:
26-
"""Asynchronously run function *func* in a separate thread.
27-
28-
Any *args and **kwargs supplied for this function are directly passed
29-
to *func*. Also, the current :class:`contextvars.Context` is propagated,
30-
allowing context variables from the main thread to be accessed in the
31-
separate thread.
32-
33-
Returns a coroutine that can be awaited to get the eventual result of *func*.
34-
"""
35-
loop = asyncio.events.get_running_loop()
36-
ctx = contextvars.copy_context()
37-
func_call = functools.partial(ctx.run, func, *args, **kwargs)
38-
return await loop.run_in_executor(None, func_call)
39-
40-
4116
async def to_thread(
4217
func: Callable[T_ParamSpec, T_Retval], /, *args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs
4318
) -> T_Retval:
4419
if sniffio.current_async_library() == "asyncio":
45-
return await _asyncio_to_thread(func, *args, **kwargs)
20+
return await asyncio.to_thread(func, *args, **kwargs)
4621

4722
return await anyio.to_thread.run_sync(
4823
functools.partial(func, *args, **kwargs),
@@ -53,10 +28,7 @@ async def to_thread(
5328
def asyncify(function: Callable[T_ParamSpec, T_Retval]) -> Callable[T_ParamSpec, Awaitable[T_Retval]]:
5429
"""
5530
Take a blocking function and create an async one that receives the same
56-
positional and keyword arguments. For python version 3.9 and above, it uses
57-
asyncio.to_thread to run the function in a separate thread. For python version
58-
3.8, it uses locally defined copy of the asyncio.to_thread function which was
59-
introduced in python 3.9.
31+
positional and keyword arguments.
6032
6133
Usage:
6234

src/knockapi/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

33
__title__ = "knockapi"
4-
__version__ = "1.18.0" # x-release-please-version
4+
__version__ = "1.18.1" # x-release-please-version

tests/test_models.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from knockapi._utils import PropertyInfo
1111
from knockapi._compat import PYDANTIC_V1, parse_obj, model_dump, model_json
12-
from knockapi._models import BaseModel, construct_type
12+
from knockapi._models import DISCRIMINATOR_CACHE, BaseModel, construct_type
1313

1414

1515
class BasicModel(BaseModel):
@@ -809,7 +809,7 @@ class B(BaseModel):
809809

810810
UnionType = cast(Any, Union[A, B])
811811

812-
assert not hasattr(UnionType, "__discriminator__")
812+
assert not DISCRIMINATOR_CACHE.get(UnionType)
813813

814814
m = construct_type(
815815
value={"type": "b", "data": "foo"}, type_=cast(Any, Annotated[UnionType, PropertyInfo(discriminator="type")])
@@ -818,7 +818,7 @@ class B(BaseModel):
818818
assert m.type == "b"
819819
assert m.data == "foo" # type: ignore[comparison-overlap]
820820

821-
discriminator = UnionType.__discriminator__
821+
discriminator = DISCRIMINATOR_CACHE.get(UnionType)
822822
assert discriminator is not None
823823

824824
m = construct_type(
@@ -830,7 +830,7 @@ class B(BaseModel):
830830

831831
# if the discriminator details object stays the same between invocations then
832832
# we hit the cache
833-
assert UnionType.__discriminator__ is discriminator
833+
assert DISCRIMINATOR_CACHE.get(UnionType) is discriminator
834834

835835

836836
@pytest.mark.skipif(PYDANTIC_V1, reason="TypeAliasType is not supported in Pydantic v1")

0 commit comments

Comments
 (0)