Skip to content

Commit 999cbf5

Browse files
NO-SNOW: Simplify callable instance into function
1 parent 9e76506 commit 999cbf5

File tree

3 files changed

+24
-32
lines changed

3 files changed

+24
-32
lines changed

src/snowflake/connector/aio/__init__.py

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

33
from functools import wraps
4-
from typing import (
5-
Any,
6-
Coroutine,
7-
Generator,
8-
Protocol,
9-
TypeVar,
10-
runtime_checkable,
11-
)
4+
from typing import Any, Coroutine, Generator, Protocol, TypeVar, runtime_checkable
125

136
from ._connection import SnowflakeConnection
147
from ._cursor import DictCursor, SnowflakeCursor
@@ -98,8 +91,6 @@ async def __aexit__(
9891
...
9992

10093

101-
102-
10394
class _AsyncConnectContextManager(HybridCoroutineContextManager[SnowflakeConnection]):
10495
"""Hybrid wrapper that enables both awaiting and async context manager usage.
10596
@@ -160,6 +151,7 @@ def Connect(**kwargs: Any) -> HybridCoroutineContextManager[SnowflakeConnection]
160151
- conn = await connect(...)
161152
- async with connect(...) as conn:
162153
"""
154+
163155
async def _connect_coro() -> SnowflakeConnection:
164156
conn = SnowflakeConnection(**kwargs)
165157
await conn.connect()
@@ -168,4 +160,4 @@ async def _connect_coro() -> SnowflakeConnection:
168160
return _AsyncConnectContextManager(_connect_coro())
169161

170162

171-
connect = Connect
163+
connect = Connect

test/integ/test_connection.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,15 +1629,15 @@ def test_connect_metadata_preservation():
16291629
assert callable(connect), "connect should be callable"
16301630

16311631
# Test 9: Check type() and __class__ values (important for user introspection)
1632-
assert type(connect).__name__ == "function", (
1633-
f"type(connect).__name__ should be 'function', but got '{type(connect).__name__}'"
1634-
)
1635-
assert connect.__class__.__name__ == "function", (
1636-
f"connect.__class__.__name__ should be 'function', but got '{connect.__class__.__name__}'"
1637-
)
1638-
assert inspect.isfunction(connect), (
1639-
"connect should be recognized as a function by inspect.isfunction()"
1640-
)
1632+
assert (
1633+
type(connect).__name__ == "function"
1634+
), f"type(connect).__name__ should be 'function', but got '{type(connect).__name__}'"
1635+
assert (
1636+
connect.__class__.__name__ == "function"
1637+
), f"connect.__class__.__name__ should be 'function', but got '{connect.__class__.__name__}'"
1638+
assert inspect.isfunction(
1639+
connect
1640+
), "connect should be recognized as a function by inspect.isfunction()"
16411641

16421642
# Test 10: Verify the function has proper introspection capabilities
16431643
# IDEs and type checkers should be able to resolve parameters

test/unit/aio/test_connection_async_unit.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -877,9 +877,9 @@ async def test_connect_metadata_preservation():
877877
from snowflake.connector.aio import SnowflakeConnection, connect
878878

879879
# Test 1: Check __name__ is correct
880-
assert connect.__name__ == "__init__", (
881-
f"connect.__name__ should be '__init__', but got '{connect.__name__}'"
882-
)
880+
assert (
881+
connect.__name__ == "__init__"
882+
), f"connect.__name__ should be '__init__', but got '{connect.__name__}'"
883883
assert (
884884
connect.__qualname__ == "SnowflakeConnection.__init__"
885885
), f"connect.__qualname__ should be 'connect', but got '{connect.__qualname__}'"
@@ -936,15 +936,15 @@ async def test_connect_metadata_preservation():
936936
assert callable(connect), "connect should be callable"
937937

938938
# Test 9: Check type() and __class__ values (important for user introspection)
939-
assert type(connect).__name__ == "function", (
940-
f"type(connect).__name__ should be 'function', but got '{type(connect).__name__}'"
941-
)
942-
assert connect.__class__.__name__ == "function", (
943-
f"connect.__class__.__name__ should be 'function', but got '{connect.__class__.__name__}'"
944-
)
945-
assert inspect.isfunction(connect), (
946-
"connect should be recognized as a function by inspect.isfunction()"
947-
)
939+
assert (
940+
type(connect).__name__ == "function"
941+
), f"type(connect).__name__ should be 'function', but got '{type(connect).__name__}'"
942+
assert (
943+
connect.__class__.__name__ == "function"
944+
), f"connect.__class__.__name__ should be 'function', but got '{connect.__class__.__name__}'"
945+
assert inspect.isfunction(
946+
connect
947+
), "connect should be recognized as a function by inspect.isfunction()"
948948

949949
# Test 10: Verify the function has proper introspection capabilities
950950
# IDEs and type checkers should be able to resolve parameters

0 commit comments

Comments
 (0)