Skip to content

Commit 9b500d9

Browse files
committed
only apply Literal type checking for 3.8 and higher
1 parent 3f1efab commit 9b500d9

File tree

1 file changed

+11
-6
lines changed
  • sqlalchemy-stubs/dialects/postgresql

1 file changed

+11
-6
lines changed

sqlalchemy-stubs/dialects/postgresql/base.pyi

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +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, TypeVar, overload, Literal
4+
from typing import Any, Optional, Set, Type, Text, Pattern, Dict, TypeVar
55
from datetime import timedelta
6-
import uuid
6+
import sys
77

88
from sqlalchemy.types import INTEGER as INTEGER, BIGINT as BIGINT, SMALLINT as SMALLINT, VARCHAR as VARCHAR, \
99
CHAR as CHAR, TEXT as TEXT, FLOAT as FLOAT, NUMERIC as NUMERIC, \
@@ -72,10 +72,15 @@ _T = TypeVar("_T")
7272
class UUID(sqltypes.TypeEngine[_T]):
7373
__visit_name__: str = ...
7474
as_uuid: bool = ...
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]]: ...
75+
if sys.version_info() >= (3,8):
76+
# Literal type is only supported since 3.8
77+
from typing import Literal, overload
78+
import uuid
79+
@overload
80+
def __new__(self, as_uuid: Literal[True]) -> UUID[sqltypes.TypeEngine[uuid.UUID]]: ...
81+
@overload
82+
def __new__(self, as_uuid: Literal[False, None]) -> UUID[sqltypes.TypeEngine[str]]: ...
83+
7984
def __new__(self) -> UUID[sqltypes.TypeEngine[str]]: ...
8085
def bind_processor(self, dialect: Any): ...
8186
def result_processor(self, dialect: Any, coltype: Any): ...

0 commit comments

Comments
 (0)