Skip to content

Commit 4689c3c

Browse files
authored
Merge pull request #91 from KotlinIsland/fix-overload
fix overload
2 parents 01ac8d0 + af5bd49 commit 4689c3c

File tree

3 files changed

+45
-34
lines changed

3 files changed

+45
-34
lines changed

basedtyping/__init__.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import contextlib
56
import sys
67
from typing import (
78
TYPE_CHECKING,
@@ -21,17 +22,24 @@
2122
)
2223

2324
import typing_extensions
24-
from typing_extensions import (
25-
Never,
26-
ParamSpec,
27-
TypeAlias,
28-
TypeGuard,
29-
TypeVarTuple,
30-
override,
31-
)
25+
from typing_extensions import Never, ParamSpec, TypeAlias, TypeGuard, TypeVarTuple
3226

3327
from basedtyping.runtime_only import OldUnionType
3428

29+
if TYPE_CHECKING:
30+
from typing_extensions import override
31+
else:
32+
33+
def override(arg, /):
34+
# TODO: Remove when typing_extensions is >= 4.4
35+
with contextlib.suppress(AttributeError, TypeError):
36+
# Skip the attribute silently if it is not writable.
37+
# AttributeError happens if the object has __slots__ or a
38+
# read-only property, TypeError if it's a builtin class.
39+
arg.__override__ = True
40+
return arg
41+
42+
3543
if not TYPE_CHECKING:
3644
# TODO: remove the TYPE_CHECKING block once these are typed in basedtypeshed
3745
from typing import _GenericAlias, _remove_dups_flatten, _tp_cache, _type_check

poetry.lock

Lines changed: 28 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ version = "0.1.3"
99

1010
[tool.poetry.dependencies]
1111
python = "^3.8"
12-
typing_extensions = "^4"
12+
typing_extensions = "^4.1"
1313

1414
[tool.poetry.group.dev.dependencies]
1515
basedmypy = "^2"

0 commit comments

Comments
 (0)