githubkit 0.16.0__py3-none-any.whl → 0.16.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,8 +27,13 @@ class MemCache(AsyncBaseCache, BaseCache):
27
27
 
28
28
  @override
29
29
  def get(self, key: str) -> str | None:
30
- self.expire()
31
- return (item := self._cache.get(key, None)) and item.value
30
+ item = self._cache.get(key)
31
+ if item is None:
32
+ return None
33
+ if item.expire_at is not None and item.expire_at < datetime.now(timezone.utc):
34
+ self._cache.pop(key, None)
35
+ return None
36
+ return item.value
32
37
 
33
38
  @override
34
39
  async def aget(self, key: str) -> str | None:
@@ -36,7 +41,6 @@ class MemCache(AsyncBaseCache, BaseCache):
36
41
 
37
42
  @override
38
43
  def set(self, key: str, value: str, ex: timedelta) -> None:
39
- self.expire()
40
44
  self._cache[key] = _Item(value, datetime.now(timezone.utc) + ex)
41
45
 
42
46
  @override
githubkit/core.py CHANGED
@@ -4,7 +4,7 @@ from contextvars import ContextVar
4
4
  from datetime import datetime, timedelta, timezone
5
5
  import time
6
6
  from types import TracebackType
7
- from typing import TYPE_CHECKING, Any, Generic, TypeVar, cast, overload
7
+ from typing import TYPE_CHECKING, Any, Generic, TypeVar, overload
8
8
 
9
9
  import anyio
10
10
  import httpx
@@ -222,8 +222,11 @@ class GitHubCore(Generic[A]):
222
222
  exc_value: BaseException | None = None,
223
223
  traceback: TracebackType | None = None,
224
224
  ):
225
- cast(httpx.Client, self.__sync_client.get()).close()
226
- self.__sync_client.set(None)
225
+ if client := self.__sync_client.get():
226
+ try:
227
+ client.close()
228
+ finally:
229
+ self.__sync_client.set(None)
227
230
 
228
231
  # async context
229
232
  async def __aenter__(self):
@@ -238,8 +241,11 @@ class GitHubCore(Generic[A]):
238
241
  exc_value: BaseException | None = None,
239
242
  traceback: TracebackType | None = None,
240
243
  ):
241
- await cast(httpx.AsyncClient, self.__async_client.get()).aclose()
242
- self.__async_client.set(None)
244
+ if client := self.__async_client.get():
245
+ try:
246
+ await client.aclose()
247
+ finally:
248
+ self.__async_client.set(None)
243
249
 
244
250
  def _get_client_defaults(self) -> dict[str, Any]:
245
251
  """Get default arguments for creating a httpx client."""
githubkit/throttling.py CHANGED
@@ -37,19 +37,24 @@ class LocalThrottler(BaseThrottler):
37
37
 
38
38
  def __init__(self, max_concurrency: int) -> None:
39
39
  self.max_concurrency = max_concurrency
40
+ self._lock = threading.Lock()
40
41
  self._semaphore: threading.Semaphore | None = None
41
42
  self._async_semaphore: anyio.Semaphore | None = None
42
43
 
43
44
  @property
44
45
  def semaphore(self) -> threading.Semaphore:
45
46
  if self._semaphore is None:
46
- self._semaphore = threading.Semaphore(self.max_concurrency)
47
+ with self._lock:
48
+ if self._semaphore is None:
49
+ self._semaphore = threading.Semaphore(self.max_concurrency)
47
50
  return self._semaphore
48
51
 
49
52
  @property
50
53
  def async_semaphore(self) -> anyio.Semaphore:
51
54
  if self._async_semaphore is None:
52
- self._async_semaphore = anyio.Semaphore(self.max_concurrency)
55
+ with self._lock:
56
+ if self._async_semaphore is None:
57
+ self._async_semaphore = anyio.Semaphore(self.max_concurrency)
53
58
  return self._async_semaphore
54
59
 
55
60
  @override
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: GitHubKit
3
- Version: 0.16.0
3
+ Version: 0.16.1
4
4
  Summary: GitHub SDK for Python
5
5
  Keywords: github,octokit
6
6
  Author: yanyongyu
@@ -9,11 +9,11 @@ githubkit/auth/token.py,sha256=Lv-HTq7w7DDUXiLmFZXlOyqdk3UHtr82jerJNJ07sWY,808
9
9
  githubkit/auth/unauth.py,sha256=-cqSpOe7fudZUORFSqp-XDf7GOMdUiwwTV0uEGSNk5o,315
10
10
  githubkit/cache/__init__.py,sha256=3TR87D9iKoXWCFLbxwQ4j21NEWi2k_mRfdp2fi6ErqU,526
11
11
  githubkit/cache/base.py,sha256=cuMAI_zZxpLflgflyDSMvapJuBJjyN7mIzhVD8dRwh0,1817
12
- githubkit/cache/mem_cache.py,sha256=oiNxo50vmbFniJI8q9PkQqYxlESIovl_WzbjN33rnbw,2860
12
+ githubkit/cache/mem_cache.py,sha256=3ars53UodEcBWpKwCWh6fW4T72uqbHIgeJUbio9iYAI,3010
13
13
  githubkit/cache/redis.py,sha256=9gIR_yM9DKe5jseVTdPoSNyWiVTcfYPdSmXJu7-TYFc,3687
14
14
  githubkit/compat.py,sha256=WSjLtUSTaDvcpI6rYgHX3q00WYT8KrY_2iMF4om96Ck,4422
15
15
  githubkit/config.py,sha256=OiqoqFpm2U2LARYKhJgseXQwoCXulloz12xune8OQhs,4647
16
- githubkit/core.py,sha256=P97PXnTs3TU0Rs5l6mH7lcQOxSqrkoupQlpTS2AV6yM,22834
16
+ githubkit/core.py,sha256=IvAao-clQQ-qQWRNQGoPdBsnOxKyiJ0TKiN6-Fgsyp4,22949
17
17
  githubkit/exception.py,sha256=2NFjBipaVD9fJN1rMcMM2xp8GD4yENncDyWkvhvmVW8,3635
18
18
  githubkit/github.py,sha256=L7fSGssp4nnCwXiAXJwUa1p37P0Rk4LZqyhpz4vh35Y,5695
19
19
  githubkit/graphql/__init__.py,sha256=MStdVc-FHZsNsC_uw2nNpyWISzUDa5-zFp6Wl61j-QQ,4255
@@ -29,11 +29,11 @@ githubkit/response.py,sha256=SVukjbQMUXtvcCsKT9zRaiCg4aKJsb6SXwozMd32qII,4980
29
29
  githubkit/rest/__init__.py,sha256=DTaKS1CHYS7O_DxFNs-jP4_w11OOSXWwiI35rzBVw7Q,46
30
30
  githubkit/rest/paginator.py,sha256=jx2yCuIQnYK9Z4r2X3TqB5o1Ia2DvzsPQL20NIuAKnk,6999
31
31
  githubkit/retry.py,sha256=priynVVm1EX8Mm4-GFdkdd0bc-GnSFWAKyO0bBMQZC4,2634
32
- githubkit/throttling.py,sha256=ZfqHft90jct8puHb46Dw3cTVKOXqajPnbzbnYZm8UJQ,2073
32
+ githubkit/throttling.py,sha256=MHlp9_sXXimYjAnshoqvHHvSmjyih3pBdSmIbHEEnkE,2279
33
33
  githubkit/typing.py,sha256=uNJKizINpYe-FT4gYJ17vDy0qkAjPxnXM4uJKjMf4_c,2454
34
34
  githubkit/utils.py,sha256=a14fYxSSbxNl8a7sfwGTNtomMEMWOkKWudTweVEvVIA,3588
35
35
  githubkit/versions/__init__.py,sha256=iU0jkOOsjxzpW88tnZENRU7non3y24HgbRbw4w93n1Y,352
36
36
  githubkit/webhooks/__init__.py,sha256=UsbIdIOJs53fzuxEMyvgEboELygLUt-4CrmHk1LefWA,385
37
- githubkit-0.16.0.dist-info/WHEEL,sha256=8ZlpUMJ7mlDirmlHRhDirEx_nPnARrwDjeE92mlk68E,81
38
- githubkit-0.16.0.dist-info/METADATA,sha256=esXo8DZTz0vxzx-WMi8ckelKFPOd8SwQhx6EO0zHXW0,5529
39
- githubkit-0.16.0.dist-info/RECORD,,
37
+ githubkit-0.16.1.dist-info/WHEEL,sha256=nQ0eT7mepDP-DkLACRDiCUi7cAIJyLg4OevuC4KpLLY,80
38
+ githubkit-0.16.1.dist-info/METADATA,sha256=hHWXSuqZwZ_jkbr3JkIi0ECABEAJ3bBFaJsdceJziJM,5529
39
+ githubkit-0.16.1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: uv 0.11.21
2
+ Generator: uv 0.12.4
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any