Repository: Kludex/no-optional (language: python)

Issue:
Support `List[Optional[str]]` for example
Hi @Kludex!
I actually used your lib on our code base before using another script to change `Union` into `|`.
Thanks for that! ❤️ 
But I had to do some manual changes since things like `List[Optional[str]]`, `Dict[str, Optional[str]]`, ... are currently ignored.
I don't know if it's something you want to work on and I'm sorry I don't have time to do it myself.
Cheers


Discussion / hints:
Ofc, I'll work on it tomorrow. 😁

I didn't notice that case. Thanks! 🙏

Btw, was it bothersome to use the libcst CLI instead of having a native one?

Fix patch:
diff --git a/no_optional/main.py b/no_optional/main.py
index 121507e..fdc5502 100644
--- a/no_optional/main.py
+++ b/no_optional/main.py
@@ -4,16 +4,6 @@
 
 
 class NoOptionalCommand(VisitorBasedCodemodCommand):
-    @m.call_if_inside(
-        m.Annotation(
-            annotation=m.Subscript(
-                value=m.Name(value="Optional")
-                | m.Attribute(
-                    value=m.Name(value="typing"), attr=m.Name(value="Optional")
-                )
-            )
-        )
-    )
     @m.leave(
         m.Subscript(
             value=m.Name(value="Optional")


Test patch:
diff --git a/tests/test_transformer.py b/tests/test_transformer.py
index 3b97461..bad3989 100644
--- a/tests/test_transformer.py
+++ b/tests/test_transformer.py
@@ -76,6 +76,42 @@ class Potato:
             """
             ),
         ),
+        (
+            textwrap.dedent(
+                """
+            from typing import List, Optional
+
+            def function(a: List[Optional[int]]) -> Optional[int]:
+                ...
+            """
+            ),
+            textwrap.dedent(
+                """
+            from typing import List, Union
+
+            def function(a: List[Union[int, None]]) -> Union[int, None]:
+                ...
+            """
+            ),
+        ),
+        (
+            textwrap.dedent(
+                """
+            from typing import Dict, Optional
+
+            def function(a: Dict[str, Optional[int]]) -> Optional[int]:
+                ...
+            """
+            ),
+            textwrap.dedent(
+                """
+            from typing import Dict, Union
+
+            def function(a: Dict[str, Union[int, None]]) -> Union[int, None]:
+                ...
+            """
+            ),
+        ),
     ),
 )
 def test_transformer(input: str, expected: str) -> None: