Enable mypy check for torch/_inductor/codegen/cpp.py
Labels: triaged, open source, module: inductor, ciflow/inductor

Fixes [#105230](https://github.com/pytorch/pytorch/issues/105230)

Summary:

As suggested in [#105230](https://github.com/pytorch/pytorch/issues/105230) mypy checking is enabled in torch/_inductor/codegen/cpp.py.

Before the fix:
```
mypy --follow-imports=skip torch/_inductor/codegen/cpp.py
torch/_inductor/codegen/cpp.py:390:9: error: Attribute "current_node" already defined on line 383  [no-redef]
torch/_inductor/codegen/cpp.py:1184:38: error: Name "Tuple" is not defined  [name-defined]
torch/_inductor/codegen/cpp.py:1184:38: note: Did you forget to import it from "typing"? (Suggestion: "from typing import Tuple")
torch/_inductor/codegen/cpp.py:1189:15: error: Value of type "Optional[Any]" is not indexable  [index]
torch/_inductor/codegen/cpp.py:1204:16: error: Cannot determine type of "cse"  [has-type]
torch/_inductor/codegen/cpp.py:1204:34: error: Cannot determine type of "loads"  [has-type]
torch/_inductor/codegen/cpp.py:1219:9: error: Cannot determine type of "stores"  [has-type]
torch/_inductor/codegen/cpp.py:1229:13: error: Cannot determine type of "loads"  [has-type]
torch/_inductor/codegen/cpp.py:1237:13: error: Cannot determine type of "stores"  [has-type]
torch/_inductor/codegen/cpp.py:1240:21: error: Value of type "Optional[Any]" is not indexable  [index]
torch/_inductor/codegen/cpp.py:1265:13: error: Cannot determine type of "stores"  [has-type]
torch/_inductor/codegen/cpp.py:1269:18: error: Cannot determine type of "cse"  [has-type]
torch/_inductor/codegen/cpp.py:1294:13: error: Value of type "Optional[Any]" is not indexable  [index]
torch/_inductor/codegen/cpp.py:1295:13: error: Value of type "Optional[Any]" is not indexable  [index]
torch/_inductor/codegen/cpp.py:1304:13: error: Value of type "Optional[Any]" is not indexable  [index]
torch/_inductor/codegen/cpp.py:1414:18: error: Cannot determine type of "loads"  [has-type]
torch/_inductor/codegen/cpp.py:1414:30: error: Cannot determine type of "compute"  [has-type]
torch/_inductor/codegen/cpp.py:1414:44: error: Cannot determine type of "stores"  [has-type]
torch/_inductor/codegen/cpp.py:1414:57: error: Cannot determine type of "cse"  [has-type]
torch/_inductor/codegen/cpp.py:1418:20: error: Cannot determine type of "cse"  [has-type]
torch/_inductor/codegen/cpp.py:1450:22: error: Value of type "Optional[Any]" is not indexable  [index]
torch/_inductor/codegen/cpp.py:1507:22: error: Value of type "Optional[Any]" is not indexable  [index]
torch/_inductor/codegen/cpp.py:1660:25: error: Name "reduction_type" is not defined  [name-defined]
torch/_inductor/codegen/cpp.py:1703:29: error: Value of type "Optional[Any]" is not indexable  [index]
torch/_inductor/codegen/cpp.py:1707:23: error: Value of type "Optional[Any]" is not indexable  [index]
torch/_inductor/codegen/cpp.py:1708:27: error: Value of type "Optional[Any]" is not indexable  [index]
torch/_inductor/codegen/cpp.py:1709:31: error: Value of type "Optional[Any]" is not indexable  [index]
torch/_inductor/codegen/cpp.py:1710:17: error: Value of type "Optional[Any]" is not indexable  [index]
torch/_inductor/codegen/cpp.py:1712:31: error: Value of type "Optional[Any]" is not indexable  [index]
torch/_inductor/codegen/cpp.py:1713:17: error: Value of type "Optional[Any]" is not indexable  [index]
torch/_inductor/codegen/cpp.py:1723:43: error: Value of type "Optional[Any]" is not indexable  [index]
torch/_inductor/codegen/cpp.py:1849:37: error: "list" is not subscriptable, use "typing.List" instead  [misc]
torch/_inductor/codegen/cpp.py:1856:38: error: "list" is not subscriptable, use "typing.List" instead  [misc]
torch/_inductor/codegen/cpp.py:1864:28: error: "list" is not subscriptable, use "typing.List" instead  [misc]
torch/_inductor/codegen/cpp.py:2081:13: error: Invalid signature "Callable[[Any], Any]" for "__getattr__"  [misc]
torch/_inductor/codegen/cpp.py:2114:33: error: Need type annotation for "i32_iinfo"  [var-annotated]
torch/_inductor/codegen/cpp.py:2122:33: error: Need type annotation for "f32_iinfo"  [var-annotated]
torch/_inductor/codegen/cpp.py:2150:28: error: Argument 1 to "len" has incompatible type "Optional[Any]"; expected "Sized"  [arg-type]
torch/_inductor/codegen/cpp.py:2151:28: error: Argument 1 to "len" has incompatible type "Optional[Any]"; expected "Sized"  [arg-type]
torch/_inductor/codegen/cpp.py:2153:34: error: Item "None" of "Optional[Any]" has no attribute "__iter__" (not iterable)  [union-attr]
torch/_inductor/codegen/cpp.py:2163:41: error: Argument 1 to "zip" has incompatible type "Optional[Any]"; expected "Iterable[Any]"  [arg-type]
torch/_inductor/codegen/cpp.py:2163:56: error: Argument 2 to "zip" has incompatible type "Optional[Any]"; expected "Iterable[Any]"  [arg-type]
torch/_inductor/codegen/cpp.py:2172:37: error: Need type annotation for "i32_iinfo"  [var-annotated]
torch/_inductor/codegen/cpp.py:2189:32: error: Argument 1 to "len" has incompatible type "Optional[Any]"; expected "Sized"  [arg-type]
torch/_inductor/codegen/cpp.py:2205:34: error: Value of type "Optional[Any]" is not indexable  [index]
torch/_inductor/codegen/cpp.py:2636:29: error: Argument 1 to "len" has incompatible type "Optional[Any]"; expected "Sized"  [arg-type]
torch/_inductor/codegen/cpp.py:2646:51: error: Argument 1 to "len" has incompatible type "Optional[Any]"; expected "Sized"  [arg-type]
torch/_inductor/codegen/cpp.py:2699:46: error: Argument 1 to "len" has incompatible type "Optional[Any]"; expected "Sized"  [arg-type]
torch/_inductor/codegen/cpp.py:2738:33: error: Incompatible types in assignment (expression has type "KernelGroup", variable has type "CppWrapperKernelGroup")  [assignment]
torch/_inductor/codegen/cpp.py:2909:41: error: Incompatible types in assignment (expression has type "None", variable has type "Dict[str, str]")  [assignment]
torch/_inductor/codegen/cpp.py:2910:27: error: Incompatible types in assignment (expression has type "None", variable has type "LoopLevel")  [assignment]
torch/_inductor/codegen/cpp.py:2915:25: error: Incompatible types in assignment (expression has type "None", variable has type "CppKernel")  [assignment]
torch/_inductor/codegen/cpp.py:3067:29: error: Incompatible types in assignment (expression has type "None", variable has type "List[LoopLevel]")  [assignment]
torch/_inductor/codegen/cpp.py:3068:25: error: Incompatible types in assignment (expression has type "None", variable has type "CppKernel")  [assignment]
torch/_inductor/codegen/cpp.py:3079:27: error: Incompatible types in assignment (expression has type "None", variable has type "LoopLevel")  [assignment]
torch/_inductor/codegen/cpp.py:3080:52: error: Argument 1 to "zip" has incompatible type "Optional[Any]"; expected "Iterable[Any]"  [arg-type]
torch/_inductor/codegen/cpp.py:3080:62: error: Argument 2 to "zip" has incompatible type "Optional[Any]"; expected "Iterable[Any]"  [arg-type]
torch/_inductor/codegen/cpp.py:3082:16: error: Unsupported operand types for >= ("int" and "None")  [operator]
torch/_inductor/codegen/cpp.py:3082:16: note: Right operand is of type "Optional[Any]"
torch/_inductor/codegen/cpp.py:3086:45: error: Argument 2 to "LoopNestWithSplit" has incompatible type "int"; expected "CppKernel"  [arg-type]
torch/_inductor/codegen/cpp.py:3086:49: error: Argument 1 to "len" has incompatible type "Optional[Any]"; expected "Sized"  [arg-type]
Found 59 errors in 1 file (checked 1 source file)
```

After the fix:
```
mypy --follow-imports=skip torch/_inductor/codegen/cpp.py  
Success: no issues found in 1 source file
```

Reviewers: @eellison

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @Xia-Weiwen @wenzhe-nrv @jiayisunx @peterbell10 @ipiszy @ngimel @yf225 @chenyang78 @kadeng @muchulee8 @aakhundov