hauntsaninja / no_implicit_optional

A codemod to make your implicit optional type hints PEP 484 compliant.
MIT License
79 stars 8 forks source link

Tool does not correctly respect typing.Annotated #3

Closed silasary closed 1 year ago

silasary commented 1 year ago

typing.Annotated allows for annotations to have both a type annotation, and also additional data.

When encountered, the typing annotation is the first generic parameter, and any additional parameters are bonus data.

The tool currently doesn't acknowledge that, and wraps the whole Annotated annotation in an Optional.

Expected:

-async def offending(param: Annotated[str, str.isdigit] = None) -> None:
+async def offending(param: Annotated[Optional[str], str.isdigit] = None) -> None:

async def good(param: Annotated[Optional[str], str.isdigit] = None) -> None:

Current Output:

-async def offending(param: Annotated[str, str.isdigit] = None) -> None:
+async def offending(param: Optional[Annotated[str, str.isdigit]] = None) -> None:

-async def good(param: Annotated[Optional[str], str.isdigit] = None) -> None:
+async def good(param: Optional[Annotated[Optional[str], str.isdigit]] = None) -> None:
hauntsaninja commented 1 year ago

Thanks! This should be fixed, just released v1.1