Skip to content

[docker] Add missing type annotations in docker.types#15566

Open
emmanuel-ferdman wants to merge 1 commit intopython:mainfrom
emmanuel-ferdman:docker-fix-types
Open

[docker] Add missing type annotations in docker.types#15566
emmanuel-ferdman wants to merge 1 commit intopython:mainfrom
emmanuel-ferdman:docker-fix-types

Conversation

@emmanuel-ferdman
Copy link
Copy Markdown
Contributor

PR Summary

This PR replaces all Incomplete types in docker.types with specific types verified against the docker-py runtime.

Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
@github-actions
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some preliminary notes about Any, not a full review.

Please note that each use of Any must be well-argument using code comments.

Comment on lines +4 to +5
class DictType(dict[str, Any]):
def __init__(self, init: Mapping[str, Any]) -> None: ...
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should use Any as value type. If the dict is generic over the value type, we should use a TypeVar like dict does.

class LogConfig(DictType):
types: type[LogConfigTypesEnum]
def __init__(self, **kwargs) -> None: ...
def __init__(self, **kwargs: Any) -> None: ...
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any is not the best we can do here. Looking at the code, LogConfig.__init__ supports two keyword arguments type and config (which may also be spelled Type and Config). All other keyword arguments are ignored. We should represent that in the stubs. For example, like this:

Suggested change
def __init__(self, **kwargs: Any) -> None: ...
def __init__(self, *, type: str, Type: str, config: dict[str, Incomplete], Config: dict[str, Incomplete]) -> None: ...

or this

Suggested change
def __init__(self, **kwargs: Any) -> None: ...
def __init__(self, *, type: str, Type: str, config: dict[str, Incomplete], Config: dict[str, Incomplete], **kwargs: Unused) -> None: ...

(Depending on whether providing extra, unused keyword arguments is expected or as potential error.)

An advanced version would use overloads to prevent type and Type or config and Config at the same time.

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.

2 participants