cloudtools / awacs

Python library for AWS Access Policy Language creation
BSD 2-Clause "Simplified" License
396 stars 102 forks source link

Add type hints and check them with mypy #165

Closed michael-k closed 3 years ago

michael-k commented 3 years ago

The file py.typed makes the type hints available for use in other projects.

There are still a lot of Anys. In some of those cases Any is fine (__eq__, __ne__, …), but in others I wasn't sure if I can come up with a complete list of allowed values. Eg. what does Principal accept as resources? Maybe ↓?

from typing import TYPE_CHECKING, Union, Sequence

if TYPE_CHECKING:
    from troposphere import Ref
    from .iam import ARN as IAM_ARN

Resources = Union[str, "IAM_ARN", "Ref", Sequence[Union[str, "IAM_ARN", "Ref"]]

class Principal(AWSHelperFn):
    def __init__(self, principal: str, resources: Resources = None) -> None:
        ...

troposphere.Ref makes it hard/impossible to properly restrict the type hints because awacs does not depend on troposphere and then troposphere.Ref is just Any for all projects that use awacs without troposphere.


Maybe declare (note in changelog) type hints as experimental in the next release to (formally) allow changes without the need of a major version bump.

markpeek commented 3 years ago

Thanks!