Skip to content

[ldap3] Annotate generator functions as returning iterators - #16723

Open
Dhairya-007 wants to merge 1 commit into
python:mainfrom
Dhairya-007:ldap3-generator-returns
Open

Dhairya-007 wants to merge 1 commit into
python:mainfrom
Dhairya-007:ldap3-generator-returns

Conversation

@Dhairya-007

Copy link
Copy Markdown
Contributor

paged_search_generator, PersistentSearch.funnel and ADPersistentSearch.funnel are generators, but all three were declared -> None, so iterating them — the only way to use them — was a type error:

for entry in paged_search_generator(conn, base, "(objectClass=*)"):
    ...
# error: "None" has no attribute "__iter__" (not iterable)  [attr-defined]
# error: "paged_search_generator" does not return a value  [func-returns-value]

A short usage file reports 4 errors before this change and none after.

Checked against ldap3 2.9.1: each one contains a yield outside any nested function. paged_search_generator yields entries off the response list (yield responses.pop()), and both funnel methods yield search result entries from the event queue.

Annotated as Iterator[Incomplete], matching the element type used throughout these stubs. The sibling next methods are left unannotated exactly as they were.

stubtest does not compare return types, which is why this was invisible. It reports the same single pre-existing error before and after (ldap3.protocol.sasl.kerberos requires the optional gssapi package), mypy reports the same 25 pre-existing pyasn1 import errors in both cases, and pyright, ruff and black are clean.

`paged_search_generator`, `PersistentSearch.funnel` and
`ADPersistentSearch.funnel` are generators, but were declared `-> None`,
so iterating them was a type error:

    for entry in paged_search_generator(conn, base, "(objectClass=*)"):
        ...
    # error: "None" has no attribute "__iter__" (not iterable)

All three yield outside any nested function in ldap3 2.9.1:
`paged_search_generator` yields entries off the response list, and both
`funnel` methods yield search result entries. Annotated
`Iterator[Incomplete]` to match the element type the rest of these stubs
use; the sibling `next` methods are deliberately left unannotated as
they already were.

stubtest reports the same single pre-existing error before and after
(`ldap3.protocol.sasl.kerberos` needs the optional gssapi package), and
mypy reports the same 25 pre-existing pyasn1 import errors. pyright is
clean.
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant