From 5f56b0707bd71b1be050e212cd31e64139340fbb Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Fri, 29 Nov 2019 19:55:09 +0100 Subject: [PATCH] Add stub type hints - even if not working Apparently PEP561 only addresses packages, not modules, and somewhat dismissively says: "code should be refactored into a package-based distribution and indicate that the package supports typing as described above". Well, locally I can use it, so let's add the stub. Will see later if it can be used somehow. --- MANIFEST.in | 2 ++ Makefile | 5 +++- posix1e.pyi | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++ py.typed | 0 setup.py | 5 ++++ 5 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 posix1e.pyi create mode 100644 py.typed diff --git a/MANIFEST.in b/MANIFEST.in index 1da4844..9c9a87d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -7,3 +7,5 @@ include setup.cfg include doc/conf.py include doc/*.rst include tests/*.py +include py.typed +include posix1e.pyi diff --git a/Makefile b/Makefile index bde250e..4428ec3 100644 --- a/Makefile +++ b/Makefile @@ -74,4 +74,7 @@ clean: rm -f *.so rm -rf build -.PHONY: doc test clean dist coverage ci +types: + MYPYPATH=. mypy --check-untyped-defs --warn-incomplete-stub tests/test_acls.py + +.PHONY: doc test clean dist coverage ci types diff --git a/posix1e.pyi b/posix1e.pyi new file mode 100644 index 0000000..716d4a8 --- /dev/null +++ b/posix1e.pyi @@ -0,0 +1,77 @@ +# Stubs for posix1e (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Optional, Union, Tuple, TypeVar +from builtins import _PathLike as PathLike + +from typing import overload +ACL_DUPLICATE_ERROR: int +ACL_ENTRY_ERROR: int +ACL_EXECUTE: int +ACL_GROUP: int +ACL_GROUP_OBJ: int +ACL_MASK: int +ACL_MISS_ERROR: int +ACL_MULTI_ERROR: int +ACL_OTHER: int +ACL_READ: int +ACL_TYPE_ACCESS: int +ACL_TYPE_DEFAULT: int +ACL_UNDEFINED_TAG: int +ACL_USER: int +ACL_USER_OBJ: int +ACL_WRITE: int +HAS_ACL_CHECK: int +HAS_ACL_ENTRY: int +HAS_ACL_FROM_MODE: int +HAS_COPY_EXT: int +HAS_EQUIV_MODE: int +HAS_EXTENDED_CHECK: int +TEXT_ABBREVIATE: int +TEXT_ALL_EFFECTIVE: int +TEXT_NUMERIC_IDS: int +TEXT_SMART_INDENT: int +TEXT_SOME_EFFECTIVE: int + +S = TypeVar('S', str, bytes, int, PathLike) + +def delete_default(path: str) -> None: ... +def has_extended(item: S) -> bool: ... + +class ACL: + def __init__(*args, **kwargs) -> None: ... + @overload + def append(self) -> 'Entry': ... + @overload + def append(self, __entry: 'Entry') -> 'Entry': ... + def applyto(self, __item, flag: Optional[int]=0) -> None: ... + def calc_mask(self) -> None: ... + def check(self) -> Union[bool, Tuple[int, int]]: ... + def delete_entry(self, __entry: 'Entry') -> None: ... + def equiv_mode(self) -> int: ... + def to_any_text(self, prefix: str=..., separator: str=..., options: int=...) -> bytes: ... + def valid(self) -> bool: ... + def __iter__(self) -> 'ACL': ... + def __next__(self) -> 'Entry': ... + def __getstate__(self) -> bytes: ... + def __setstate__(self, state: bytes) -> None: ... + +class Entry: + parent: ACL = ... + permset: 'Permset' = ... + qualifier: int = ... + tag_type: int = ... + def __init__(self, __acl: ACL) -> None: ... + def copy(self, __src: 'Entry') -> None: ... + +class Permset: + execute: bool = ... + read: bool = ... + write: bool = ... + def __init__(self, __entry: Entry) -> None: ... + @classmethod + def add(self, perm: int) -> None: ... + def clear(self) -> None: ... + def delete(self, perm: int) -> None: ... + def test(self, perm: int) -> bool: ... diff --git a/py.typed b/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/setup.py b/setup.py index 350124d..9fe6556 100755 --- a/setup.py +++ b/setup.py @@ -46,6 +46,11 @@ setup(name="pylibacl", define_macros=macros, )], python_requires = ">=3.4", + # Note: doesn't work since it's not a package. Sigh. + package_data = { + '': ['py.typed', 'posix1e.pyi'], + }, + zip_safe=False, project_urls={ "Bug Tracker": "https://github.com/iustin/pylibacl/issues", }, -- 2.39.5