Skip to content

Commit 8db9cac

Browse files
committed
Support UUID=True
1 parent cd608f4 commit 8db9cac

File tree

1 file changed

+17
-3
lines changed
  • sqlalchemy-stubs/dialects/postgresql

1 file changed

+17
-3
lines changed

sqlalchemy-stubs/dialects/postgresql/base.pyi

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
from ... import schema
22
from ...engine import default, reflection
33
from ...sql import compiler, expression, sqltypes, type_api
4-
from typing import Any, Optional, Set, Type, Text, Pattern, Dict
4+
from typing import Any, Optional, Set, Type, Text, Pattern, Dict, TypeVar, overload
55
from datetime import timedelta
6+
import uuid
7+
import sys
68

79
from sqlalchemy.types import INTEGER as INTEGER, BIGINT as BIGINT, SMALLINT as SMALLINT, VARCHAR as VARCHAR, \
810
CHAR as CHAR, TEXT as TEXT, FLOAT as FLOAT, NUMERIC as NUMERIC, \
911
DATE as DATE, BOOLEAN as BOOLEAN, REAL as REAL
1012

13+
if sys.version_info >= (3, 8):
14+
from typing import Literal
15+
else:
16+
from typing_extensions import Literal
17+
1118
AUTOCOMMIT_REGEXP: Pattern[Text]
1219
RESERVED_WORDS: Set[str]
1320

@@ -66,10 +73,17 @@ class BIT(sqltypes.TypeEngine[str]):
6673
def __init__(self, length: Optional[int] = ..., varying: bool = ...) -> None: ...
6774
PGBit = BIT
6875

69-
class UUID(sqltypes.TypeEngine[str]):
76+
_T = TypeVar("_T")
77+
78+
class UUID(sqltypes.TypeEngine[_T]):
7079
__visit_name__: str = ...
7180
as_uuid: bool = ...
72-
def __init__(self, as_uuid: bool = ...) -> None: ...
81+
@overload
82+
def __new__(self, as_uuid: Literal[True]) -> UUID[sqltypes.TypeEngine[uuid.UUID]]: ...
83+
@overload
84+
def __new__(self, as_uuid: Literal[False, None]) -> UUID[sqltypes.TypeEngine[str]]: ...
85+
@overload
86+
def __new__(self) -> UUID[sqltypes.TypeEngine[str]]: ...
7387
def bind_processor(self, dialect: Any): ...
7488
def result_processor(self, dialect: Any, coltype: Any): ...
7589
PGUuid = UUID

0 commit comments

Comments
 (0)