Visitar URL original
refactor: centralize type aliases for reliable stub generation by spaceone · Pull Request #691 · python-ldap/python-ldap · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Lib/ldap/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from __future__ import annotations

import sys
from collections.abc import MutableMapping, Sequence
from collections.abc import Mapping, MutableMapping, Sequence
from typing import TYPE_CHECKING, Optional, Union

from ldap.pkginfo import __version__ # noqa: F401
Expand Down Expand Up @@ -65,3 +65,10 @@
LDAPSearchResult = tuple[str, LDAPEntryDict]
"""The type of a search result, a tuple with a DN string and a dict of
attributes."""

LDAPTokenDictValue: TypeAlias = Union[tuple[()], tuple[str, ...]]
"""The kind of values which may be found in a token dict."""

LDAPTokenDict: TypeAlias = Mapping[str, LDAPTokenDictValue]
"""The type of the dict used to keep track of tokens while parsing schema
(Mapping because of variance)."""
9 changes: 3 additions & 6 deletions Lib/ldap/schema/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@
from typing_extensions import Self

import ldap.schema
from ldap._types import LDAPEntryDict, TypeAlias
from ldap._types import LDAPEntryDict, LDAPTokenDict
from ldap.cidict import cidict
from ldap.schema.subentry import SCHEMA_ATTR_MAPPING, SCHEMA_CLASS_MAPPING
from ldap.schema.tokenizer import LDAPTokenDict, parse_tokens, split_tokens


EntryBase: TypeAlias = MutableMapping[str, list[bytes]]
from ldap.schema.tokenizer import parse_tokens, split_tokens


NOT_HUMAN_READABLE_LDAP_SYNTAXES = {
Expand Down Expand Up @@ -788,7 +785,7 @@ def __str__(self) -> str:
SCHEMA_ATTR_MAPPING[NameForm] = NameForm.schema_attribute


class Entry(EntryBase):
class Entry(LDAPEntryDict):
"""
Schema-aware implementation of an LDAP entry class.

Expand Down
11 changes: 2 additions & 9 deletions Lib/ldap/schema/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,11 @@
import re
import warnings
from collections.abc import Mapping
from typing import Any, Union
from typing import Any

from ldap._types import TypeAlias
from ldap._types import LDAPTokenDict, LDAPTokenDictValue


LDAPTokenDictValue: TypeAlias = Union[tuple[()], tuple[str, ...]]
"""The kind of values which may be found in a token dict."""

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

TOKENS_FINDALL = re.compile(
r'(\()' # opening parenthesis
r'|' # or
Expand Down
Loading