Skip to content

Commit 4e8b303

Browse files
committed
import Literal from typing or typing_extensions
1 parent 73c5e46 commit 4e8b303

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

sqlmodel/_compat.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
import types
23
from contextlib import contextmanager
34
from contextvars import ContextVar
@@ -62,6 +63,12 @@ def _is_union_type(t: Any) -> bool:
6263
return t is UnionType or t is Union
6364

6465

66+
if sys.version_info >= (3, 9):
67+
from typing import Literal
68+
else:
69+
from typing_extensions import Literal
70+
71+
6572
finish_init: ContextVar[bool] = ContextVar("finish_init", default=True)
6673

6774

sqlmodel/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@
5252
from sqlalchemy.orm.instrumentation import is_instrumented
5353
from sqlalchemy.sql.schema import MetaData
5454
from sqlalchemy.sql.sqltypes import LargeBinary, Time, Uuid
55-
from typing_extensions import Literal, TypeAlias, deprecated, get_origin
55+
from typing_extensions import TypeAlias, deprecated, get_origin
5656

5757
from ._compat import ( # type: ignore[attr-defined]
5858
IS_PYDANTIC_V2,
5959
PYDANTIC_MINOR_VERSION,
6060
BaseConfig,
61+
Literal,
6162
ModelField,
6263
ModelMetaclass,
6364
Representation,

tests/test_main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
from typing import List, Literal, Optional
1+
from typing import List, Optional
22

33
import pytest
44
from sqlalchemy.exc import IntegrityError
55
from sqlalchemy.orm import RelationshipProperty
66
from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select
7+
from sqlmodel._compat import Literal
78

89

910
def test_should_allow_duplicate_row_if_unique_constraint_is_not_passed(clear_sqlmodel):

0 commit comments

Comments
 (0)