From ebe4d73fa9bfc2aa72ef136f15e5cf50957fd568 Mon Sep 17 00:00:00 2001 From: karosis88 Date: Mon, 2 Oct 2023 16:46:47 +0300 Subject: [PATCH] Version 0.05 --- .idea/.gitignore | 3 ++ .idea/anysqlite.iml | 17 ++++++ .idea/inspectionProfiles/Project_Default.xml | 52 +++++++++++++++++++ .../inspectionProfiles/profiles_settings.xml | 6 +++ .idea/misc.xml | 4 ++ .idea/modules.xml | 8 +++ .idea/vcs.xml | 6 +++ anysqlite/__init__.py | 2 +- anysqlite/_core.py | 8 ++- typetest.py | 26 ++++++++++ 10 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/anysqlite.iml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 typetest.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/anysqlite.iml b/.idea/anysqlite.iml new file mode 100644 index 0000000..5195124 --- /dev/null +++ b/.idea/anysqlite.iml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..fd95e3b --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,52 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..dd0342b --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..9a60ba1 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/anysqlite/__init__.py b/anysqlite/__init__.py index 9e064ad..0217432 100644 --- a/anysqlite/__init__.py +++ b/anysqlite/__init__.py @@ -40,4 +40,4 @@ "sqlite_version_info", "threadsafety", ] -__version__ = "0.0.4" +__version__ = "0.0.5" diff --git a/anysqlite/_core.py b/anysqlite/_core.py index 4847dcc..39a4bb4 100644 --- a/anysqlite/_core.py +++ b/anysqlite/_core.py @@ -13,7 +13,7 @@ def __init__(self, _real_connection: sqlite3.Connection) -> None: async def __aenter__(self) -> "Connection": return self - + async def __aexit__(self, *args: tp.Any, **kwargs: tp.Any) -> None: return await self.close() @@ -48,7 +48,10 @@ async def executemany( self, sql: str, seq_of_parameters: tp.Iterable[tp.Iterable[tp.Any]] ) -> "Cursor": real_cursor = await to_thread.run_sync( - self._real_connection.executemany, sql, seq_of_parameters, limiter=self._limiter + self._real_connection.executemany, + sql, + seq_of_parameters, + limiter=self._limiter, ) return Cursor(real_cursor, self._limiter) @@ -58,6 +61,7 @@ async def executescript(self, sql_script: str) -> "Cursor": ) return Cursor(real_cursor, self._limiter) + class Cursor: def __init__(self, real_cursor: sqlite3.Cursor, limiter: CapacityLimiter) -> None: self._real_cursor = real_cursor diff --git a/typetest.py b/typetest.py new file mode 100644 index 0000000..b673a40 --- /dev/null +++ b/typetest.py @@ -0,0 +1,26 @@ +import typing as tp +import sqlite3 + +P = tp.ParamSpec("P") +T = tp.TypeVar("T") +RT = tp.TypeVar("RT") + +def copy_sig(_: tp.Callable[P, T], returns: tp.Callable[..., RT]) -> tp.Callable[[tp.Callable[..., tp.Any]], tp.Callable[P, RT]]: + + def decorator(fnc: tp.Callable[..., tp.Any]) -> tp.Callable[P, RT]: + + def inner(*args, **kwargs): + return fnc(*args, **kwargs) + + return inner + + return decorator + +@copy_sig(sqlite3.connect, int.__new__) +async def connect(*args, **kwargs): + ... + + +tp.reveal_type(connect) +a = connect() +tp.reveal_type(a) \ No newline at end of file