Skip to content

Commit 3f1efab

Browse files
committed
Support UUID=True
1 parent cd608f4 commit 3f1efab

File tree

1 file changed

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

1 file changed

+10
-3
lines changed

sqlalchemy-stubs/dialects/postgresql/base.pyi

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
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, Literal
55
from datetime import timedelta
6+
import uuid
67

78
from sqlalchemy.types import INTEGER as INTEGER, BIGINT as BIGINT, SMALLINT as SMALLINT, VARCHAR as VARCHAR, \
89
CHAR as CHAR, TEXT as TEXT, FLOAT as FLOAT, NUMERIC as NUMERIC, \
@@ -66,10 +67,16 @@ class BIT(sqltypes.TypeEngine[str]):
6667
def __init__(self, length: Optional[int] = ..., varying: bool = ...) -> None: ...
6768
PGBit = BIT
6869

69-
class UUID(sqltypes.TypeEngine[str]):
70+
_T = TypeVar("_T")
71+
72+
class UUID(sqltypes.TypeEngine[_T]):
7073
__visit_name__: str = ...
7174
as_uuid: bool = ...
72-
def __init__(self, as_uuid: bool = ...) -> None: ...
75+
@overload
76+
def __new__(self, as_uuid: Literal[True]) -> UUID[sqltypes.TypeEngine[uuid.UUID]]: ...
77+
@overload
78+
def __new__(self, as_uuid: Literal[False, None]) -> UUID[sqltypes.TypeEngine[str]]: ...
79+
def __new__(self) -> UUID[sqltypes.TypeEngine[str]]: ...
7380
def bind_processor(self, dialect: Any): ...
7481
def result_processor(self, dialect: Any, coltype: Any): ...
7582
PGUuid = UUID

0 commit comments

Comments
 (0)