Skip to content

Add PEP 484 -- Type Hints #368

Description

@pmhahn

Python supports type hints to improve static analysis:
https://www.python.org/dev/peps/pep-0484/
This helps to identify cases, were wrong types are passed into functions et al by using type checkers likehttp://mypy-lang.org/ or https://github.com/google/pytype/.

python-ldap does not yet seem to contain those annotations nor am I aware of any project doing that.
Those annotation can either we added directly in the library like

def func(arg: str, val: int = 0) -> Tuple[int, str]

since Python 3.5 or in a Python-2 backward compatible way as

def func(arg, val=0): # type: (str, int) -> Tuple[int, str]

As an alternative the annotations can be put into so-called "stub files" names "*.pyi", which are collected by https://github.com/python/typeshed, but inline annotations are preferred as they are easier to keep in sync.

I started working on that, but other projects have preempted that
effort. My current work is at
univention/typeshed@8fc5f79,
but it not much more then generating the stubs using stubgen.
If someone wants to join that effort that is much appreciated.

This was proposed to the Mailing List.
@tiran proposed to start the work only after the Python 2 legacy code is removed:

we are planning to drop support for Python 3.5 and earlier in the next
version of python-ldap. This would make it simpler to add signatures for
type hints directly to the code base. Patches are welcome, but please
wait until we have finalized Python 2 cleanup in master.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions