Skip to content

Commit fdd8977

Browse files
jhall-bpborchero
andauthored
fix: Conditionally import typing-extensions (#91)
Co-authored-by: Oliver Borchert <[email protected]>
1 parent d013318 commit fdd8977

File tree

12 files changed

+71
-12
lines changed

12 files changed

+71
-12
lines changed

dataframely/_base_collection.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from __future__ import annotations
55

6+
import sys
67
import textwrap
78
import typing
89
from abc import ABCMeta
@@ -11,13 +12,17 @@
1112
from typing import Annotated, Any, cast, get_args, get_origin
1213

1314
import polars as pl
14-
from typing_extensions import Self
1515

1616
from ._filter import Filter
1717
from ._typing import LazyFrame as TypedLazyFrame
1818
from .exc import AnnotationImplementationError, ImplementationError
1919
from .schema import Schema
2020

21+
if sys.version_info >= (3, 11):
22+
from typing import Self
23+
else:
24+
from typing_extensions import Self
25+
2126
_MEMBER_ATTR = "__dataframely_members__"
2227
_FILTER_ATTR = "__dataframely_filters__"
2328

dataframely/_base_schema.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,24 @@
33

44
from __future__ import annotations
55

6+
import sys
67
import textwrap
78
from abc import ABCMeta
89
from copy import copy
910
from dataclasses import dataclass, field
1011
from typing import Any
1112

1213
import polars as pl
13-
from typing_extensions import Self
1414

1515
from ._rule import GroupRule, Rule
1616
from .columns import Column
1717
from .exc import ImplementationError
1818

19+
if sys.version_info >= (3, 11):
20+
from typing import Self
21+
else:
22+
from typing_extensions import Self
23+
1924
_COLUMN_ATTR = "__dataframely_columns__"
2025
_RULE_ATTR = "__dataframely_rules__"
2126

dataframely/_rule.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33

44
from __future__ import annotations
55

6+
import sys
67
from collections import defaultdict
78
from collections.abc import Callable
89
from typing import Any
910

1011
import polars as pl
11-
from typing_extensions import Self
12+
13+
if sys.version_info >= (3, 11):
14+
from typing import Self
15+
else:
16+
from typing_extensions import Self
1217

1318
ValidationFunction = Callable[[], pl.Expr]
1419

dataframely/collection.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: BSD-3-Clause
33

44
import json
5+
import sys
56
import warnings
67
from abc import ABC
78
from collections.abc import Mapping, Sequence
@@ -11,7 +12,6 @@
1112

1213
import polars as pl
1314
import polars.exceptions as plexc
14-
from typing_extensions import Self
1515

1616
from ._base_collection import BaseCollection, CollectionMember
1717
from ._filter import Filter
@@ -33,6 +33,11 @@
3333
from .random import Generator
3434
from .schema import _schema_from_dict
3535

36+
if sys.version_info >= (3, 11):
37+
from typing import Self
38+
else:
39+
from typing_extensions import Self
40+
3641

3742
class Collection(BaseCollection, ABC):
3843
"""Base class for all collections of data frames with a predefined schema.

dataframely/columns/_base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
from __future__ import annotations
55

66
import inspect
7+
import sys
78
from abc import ABC, abstractmethod
89
from collections import Counter
910
from collections.abc import Callable
1011
from typing import Any, TypeAlias, cast
1112

1213
import polars as pl
13-
from typing_extensions import Self
1414

1515
from dataframely._compat import pa, sa, sa_TypeEngine
1616
from dataframely._deprecation import (
@@ -20,6 +20,11 @@
2020
from dataframely._polars import PolarsDataType
2121
from dataframely.random import Generator
2222

23+
if sys.version_info >= (3, 11):
24+
from typing import Self
25+
else:
26+
from typing_extensions import Self
27+
2328
Check: TypeAlias = (
2429
Callable[[pl.Expr], pl.Expr]
2530
| list[Callable[[pl.Expr], pl.Expr]]

dataframely/columns/_mixins.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Copyright (c) QuantCo 2025-2025
22
# SPDX-License-Identifier: BSD-3-Clause
33

4+
import sys
45
from collections.abc import Sequence
56
from typing import TYPE_CHECKING, Any, Generic, Protocol, TypeVar
67

78
import polars as pl
8-
from typing_extensions import Self
99

1010
if TYPE_CHECKING: # pragma: no cover
1111
from ._base import Column
@@ -14,6 +14,11 @@
1414
else:
1515
Base = object
1616

17+
if sys.version_info >= (3, 11):
18+
from typing import Self
19+
else:
20+
from typing_extensions import Self
21+
1722
# ----------------------------------- ORDINAL MIXIN ---------------------------------- #
1823

1924

dataframely/columns/array.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
from __future__ import annotations
55

66
import math
7+
import sys
78
from collections.abc import Sequence
89
from typing import Any, Literal, cast
910

1011
import polars as pl
11-
from typing_extensions import Self
1212

1313
from dataframely._compat import pa, sa, sa_TypeEngine
1414
from dataframely.random import Generator
@@ -17,6 +17,11 @@
1717
from ._registry import column_from_dict, register
1818
from .struct import Struct
1919

20+
if sys.version_info >= (3, 11):
21+
from typing import Self
22+
else:
23+
from typing_extensions import Self
24+
2025

2126
@register
2227
class Array(Column):

dataframely/columns/list.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
from __future__ import annotations
55

6+
import sys
67
from itertools import chain
78
from typing import Any, cast
89

910
import polars as pl
10-
from typing_extensions import Self
1111

1212
from dataframely._compat import pa, sa, sa_TypeEngine
1313
from dataframely._polars import PolarsDataType
@@ -17,6 +17,11 @@
1717
from ._registry import column_from_dict, register
1818
from .struct import Struct
1919

20+
if sys.version_info >= (3, 11):
21+
from typing import Self
22+
else:
23+
from typing_extensions import Self
24+
2025

2126
@register
2227
class List(Column):

dataframely/columns/struct.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
from __future__ import annotations
55

6+
import sys
67
from typing import Any, cast
78

89
import polars as pl
9-
from typing_extensions import Self
1010

1111
from dataframely._compat import pa, sa, sa_TypeEngine
1212
from dataframely._polars import PolarsDataType
@@ -15,6 +15,11 @@
1515
from ._base import Check, Column
1616
from ._registry import column_from_dict, register
1717

18+
if sys.version_info >= (3, 11):
19+
from typing import Self
20+
else:
21+
from typing_extensions import Self
22+
1823

1924
@register
2025
class Struct(Column):

dataframely/config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
# SPDX-License-Identifier: BSD-3-Clause
33

44
import contextlib
5+
import sys
56
from types import TracebackType
67
from typing import TypedDict
78

8-
from typing_extensions import Unpack
9+
if sys.version_info >= (3, 11):
10+
from typing import Unpack
11+
else:
12+
from typing_extensions import Unpack
913

1014

1115
class Options(TypedDict):

0 commit comments

Comments
 (0)