|
1 | 1 | from ... import schema
|
2 | 2 | from ...engine import default, reflection
|
3 | 3 | 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 |
5 | 5 | from datetime import timedelta
|
| 6 | +import uuid |
| 7 | +import sys |
6 | 8 |
|
7 | 9 | from sqlalchemy.types import INTEGER as INTEGER, BIGINT as BIGINT, SMALLINT as SMALLINT, VARCHAR as VARCHAR, \
|
8 | 10 | CHAR as CHAR, TEXT as TEXT, FLOAT as FLOAT, NUMERIC as NUMERIC, \
|
9 | 11 | DATE as DATE, BOOLEAN as BOOLEAN, REAL as REAL
|
10 | 12 |
|
| 13 | +if sys.version_info >= (3, 8): |
| 14 | + from typing import Literal |
| 15 | +else: |
| 16 | + from typing_extensions import Literal |
| 17 | + |
11 | 18 | AUTOCOMMIT_REGEXP: Pattern[Text]
|
12 | 19 | RESERVED_WORDS: Set[str]
|
13 | 20 |
|
@@ -66,10 +73,17 @@ class BIT(sqltypes.TypeEngine[str]):
|
66 | 73 | def __init__(self, length: Optional[int] = ..., varying: bool = ...) -> None: ...
|
67 | 74 | PGBit = BIT
|
68 | 75 |
|
69 |
| -class UUID(sqltypes.TypeEngine[str]): |
| 76 | +_T = TypeVar("_T") |
| 77 | + |
| 78 | +class UUID(sqltypes.TypeEngine[_T]): |
70 | 79 | __visit_name__: str = ...
|
71 | 80 | 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]]: ... |
73 | 87 | def bind_processor(self, dialect: Any): ...
|
74 | 88 | def result_processor(self, dialect: Any, coltype: Any): ...
|
75 | 89 | PGUuid = UUID
|
|
0 commit comments