Skip to content

Commit c3ed69b

Browse files
committed
refactor: declare TypeAliases explicitly
Issue: #368
1 parent 2f8738b commit c3ed69b

5 files changed

Lines changed: 24 additions & 8 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,8 @@ jobs:
5050
python -V
5151
python -m pip install --upgrade pip setuptools
5252
python -m pip install --upgrade tox tox-gh-actions
53+
- name: Install typing_extensions for Python 3.9 mypy check
54+
if: matrix.python-version == '3.9'
55+
run: "python -m pip install typing_extensions"
5356
- name: "Test tox with Python ${{ matrix.python-version }}"
5457
run: "python -m tox"

Lib/ldap/_types.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@
66
from __future__ import annotations
77
from ldap.pkginfo import __version__
88

9-
from typing import MutableMapping, Optional, Sequence, Union
9+
from typing import TYPE_CHECKING, MutableMapping, Optional, Sequence, Union
10+
11+
try:
12+
from typing import TypeAlias
13+
except ImportError:
14+
if TYPE_CHECKING:
15+
from typing_extensions import TypeAlias
16+
else:
17+
TypeAlias = object
1018

1119
__all__ = [
1220
'LDAPModListAddEntry',
@@ -19,6 +27,7 @@
1927
'LDAPControlTuple',
2028
'LDAPControlTuples',
2129
'LDAPSearchResult',
30+
'TypeAlias',
2231
]
2332

2433
LDAPModListAddEntry = tuple[str, list[bytes]]

Lib/ldap/schema/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from typing_extensions import Self
1414

1515
from ldap.cidict import cidict
16-
from ldap._types import LDAPEntryDict
16+
from ldap._types import LDAPEntryDict, TypeAlias
1717

1818
import ldap.schema
1919
from ldap.schema.subentry import SCHEMA_CLASS_MAPPING, SCHEMA_ATTR_MAPPING
@@ -22,7 +22,7 @@
2222
LDAPTokenDict
2323
)
2424

25-
EntryBase = MutableMapping[str, list[bytes]]
25+
EntryBase: TypeAlias = MutableMapping[str, list[bytes]]
2626

2727

2828
NOT_HUMAN_READABLE_LDAP_SYNTAXES = {

Lib/ldap/schema/tokenizer.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88

99
import re
1010
import warnings
11-
1211
from typing import Any, Mapping, Union
1312

14-
LDAPTokenDictValue = Union[tuple[()], tuple[str, ...]]
13+
from ldap._types import TypeAlias
14+
15+
16+
LDAPTokenDictValue: TypeAlias = Union[tuple[()], tuple[str, ...]]
1517
"""The kind of values which may be found in a token dict."""
1618

17-
LDAPTokenDict = Mapping[str, LDAPTokenDictValue]
19+
LDAPTokenDict: TypeAlias = Mapping[str, LDAPTokenDictValue]
1820
"""The type of the dict used to keep track of tokens while parsing schema
1921
(Mapping because of variance)."""
2022

Lib/ldapurl.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
import html
2121
from collections.abc import MutableMapping
2222
from urllib.parse import quote, unquote
23-
2423
from typing import Iterator
2524

25+
from ldap._types import TypeAlias
26+
27+
2628
LDAP_SCOPE_BASE = 0
2729
LDAP_SCOPE_ONELEVEL = 1
2830
LDAP_SCOPE_SUBTREE = 2
@@ -141,7 +143,7 @@ def __ne__(self, other: object) -> bool:
141143
return not self.__eq__(other)
142144

143145

144-
LDAPUrlExtensionsBase = MutableMapping[str, LDAPUrlExtension]
146+
LDAPUrlExtensionsBase: TypeAlias = MutableMapping[str, LDAPUrlExtension]
145147

146148
class LDAPUrlExtensions(LDAPUrlExtensionsBase):
147149
"""

0 commit comments

Comments
 (0)