Repository: google/pytype

Issue:
Do not parse default values as types
See python/typeshed#9501.



Discussion:
@martindemello Could you take a look at this one? Based on the other usages of visit(), it looks like it has a return value, and I'm not sure if discarding that is okay or not.
you're right, annotation visitor methods should return a value because of this usage: https://github.com/google/pytype/blob/main/pytype/pyi/parser.py#L315
Traceback I'm trying to fix for reference:

<details>

```
2023-01-12T18:23:44.5631648Z Traceback (most recent call last):
2023-01-12T18:23:44.5640236Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/pyi/visitor.py", line 36, in _call_visitor
2023-01-12T18:23:44.5640765Z     return super()._call_visitor(node)
2023-01-12T18:23:44.5641526Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/ast/visitor.py", line 55, in _call_visitor
2023-01-12T18:23:44.5641927Z     return visitor(node)
2023-01-12T18:23:44.5642536Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/pyi/parser.py", line 162, in visit_Pyval
2023-01-12T18:23:44.5643008Z     return self.convert_late_annotation(node.value)
2023-01-12T18:23:44.5643714Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/pyi/parser.py", line 142, in convert_late_annotation
2023-01-12T18:23:44.5644283Z     typ = a.body[0].value  # pytype: disable=attribute-error
2023-01-12T18:23:44.5644633Z IndexError: list index out of range
2023-01-12T18:23:44.5644818Z 
2023-01-12T18:23:44.5645014Z During handling of the above exception, another exception occurred:
2023-01-12T18:23:44.5645249Z 
2023-01-12T18:23:44.5645380Z Traceback (most recent call last):
2023-01-12T18:23:44.5645809Z   File "/home/runner/work/typeshed/typeshed/./tests/pytype_test.py", line 74, in run_pytype
2023-01-12T18:23:44.5646231Z     ast = loader.load_file(_get_module_name(filename), filename)
2023-01-12T18:23:44.5646880Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 375, in load_file
2023-01-12T18:23:44.5647376Z     return self.load_module(ModuleInfo(module_name, filename), mod_ast=mod_ast)
2023-01-12T18:23:44.5648047Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 388, in load_module
2023-01-12T18:23:44.5648839Z     return self._process_module(mod_info, mod_ast)
2023-01-12T18:23:44.5649535Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 410, in _process_module
2023-01-12T18:23:44.5649956Z     module.ast = self._resolve_external_and_local_types(module.ast)
2023-01-12T18:23:44.5650623Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 363, in _resolve_external_and_local_types
2023-01-12T18:23:44.5651055Z     self._load_ast_dependencies(dependencies, lookup_ast)
2023-01-12T18:23:44.5651650Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 455, in _load_ast_dependencies
2023-01-12T18:23:44.5652034Z     dep_ast = self._import_module_by_name(name)
2023-01-12T18:23:44.5652603Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 680, in _import_module_by_name
2023-01-12T18:23:44.5653010Z     mod = self._load_builtin("stdlib", module_name)
2023-01-12T18:23:44.5653748Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 630, in _load_builtin
2023-01-12T18:23:44.5654144Z     return self.load_module(mod, mod_ast=mod_ast)
2023-01-12T18:23:44.5654700Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 388, in load_module
2023-01-12T18:23:44.5655092Z     return self._process_module(mod_info, mod_ast)
2023-01-12T18:23:44.5655666Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 410, in _process_module
2023-01-12T18:23:44.5656086Z     module.ast = self._resolve_external_and_local_types(module.ast)
2023-01-12T18:23:44.5656722Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 363, in _resolve_external_and_local_types
2023-01-12T18:23:44.5657157Z     self._load_ast_dependencies(dependencies, lookup_ast)
2023-01-12T18:23:44.5657760Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 455, in _load_ast_dependencies
2023-01-12T18:23:44.5658143Z     dep_ast = self._import_module_by_name(name)
2023-01-12T18:23:44.5658710Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 680, in _import_module_by_name
2023-01-12T18:23:44.5659104Z     mod = self._load_builtin("stdlib", module_name)
2023-01-12T18:23:44.5659650Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 630, in _load_builtin
2023-01-12T18:23:44.5660034Z     return self.load_module(mod, mod_ast=mod_ast)
2023-01-12T18:23:44.5660582Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 388, in load_module
2023-01-12T18:23:44.5660969Z     return self._process_module(mod_info, mod_ast)
2023-01-12T18:23:44.5661525Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 410, in _process_module
2023-01-12T18:23:44.5662373Z     module.ast = self._resolve_external_and_local_types(module.ast)
2023-01-12T18:23:44.5663030Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 363, in _resolve_external_and_local_types
2023-01-12T18:23:44.5663448Z     self._load_ast_dependencies(dependencies, lookup_ast)
2023-01-12T18:23:44.5664040Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 455, in _load_ast_dependencies
2023-01-12T18:23:44.5664435Z     dep_ast = self._import_module_by_name(name)
2023-01-12T18:23:44.5665003Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 680, in _import_module_by_name
2023-01-12T18:23:44.5665399Z     mod = self._load_builtin("stdlib", module_name)
2023-01-12T18:23:44.5666062Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 630, in _load_builtin
2023-01-12T18:23:44.5666491Z     return self.load_module(mod, mod_ast=mod_ast)
2023-01-12T18:23:44.5667041Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 388, in load_module
2023-01-12T18:23:44.5667430Z     return self._process_module(mod_info, mod_ast)
2023-01-12T18:23:44.5667989Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 410, in _process_module
2023-01-12T18:23:44.5668414Z     module.ast = self._resolve_external_and_local_types(module.ast)
2023-01-12T18:23:44.5669035Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 363, in _resolve_external_and_local_types
2023-01-12T18:23:44.5669462Z     self._load_ast_dependencies(dependencies, lookup_ast)
2023-01-12T18:23:44.5670053Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 455, in _load_ast_dependencies
2023-01-12T18:23:44.5670447Z     dep_ast = self._import_module_by_name(name)
2023-01-12T18:23:44.5671078Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 680, in _import_module_by_name
2023-01-12T18:23:44.5671477Z     mod = self._load_builtin("stdlib", module_name)
2023-01-12T18:23:44.5672029Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 630, in _load_builtin
2023-01-12T18:23:44.5672414Z     return self.load_module(mod, mod_ast=mod_ast)
2023-01-12T18:23:44.5672956Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 388, in load_module
2023-01-12T18:23:44.5673341Z     return self._process_module(mod_info, mod_ast)
2023-01-12T18:23:44.5673896Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 410, in _process_module
2023-01-12T18:23:44.5674307Z     module.ast = self._resolve_external_and_local_types(module.ast)
2023-01-12T18:23:44.5674938Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 363, in _resolve_external_and_local_types
2023-01-12T18:23:44.5675370Z     self._load_ast_dependencies(dependencies, lookup_ast)
2023-01-12T18:23:44.5675953Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 455, in _load_ast_dependencies
2023-01-12T18:23:44.5676345Z     dep_ast = self._import_module_by_name(name)
2023-01-12T18:23:44.5676908Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 680, in _import_module_by_name
2023-01-12T18:23:44.5677299Z     mod = self._load_builtin("stdlib", module_name)
2023-01-12T18:23:44.5677849Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 630, in _load_builtin
2023-01-12T18:23:44.5678235Z     return self.load_module(mod, mod_ast=mod_ast)
2023-01-12T18:23:44.5678780Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 388, in load_module
2023-01-12T18:23:44.5679162Z     return self._process_module(mod_info, mod_ast)
2023-01-12T18:23:44.5679706Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 410, in _process_module
2023-01-12T18:23:44.5680122Z     module.ast = self._resolve_external_and_local_types(module.ast)
2023-01-12T18:23:44.5680749Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 363, in _resolve_external_and_local_types
2023-01-12T18:23:44.5681176Z     self._load_ast_dependencies(dependencies, lookup_ast)
2023-01-12T18:23:44.5681758Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 455, in _load_ast_dependencies
2023-01-12T18:23:44.5682214Z     dep_ast = self._import_module_by_name(name)
2023-01-12T18:23:44.5682783Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 680, in _import_module_by_name
2023-01-12T18:23:44.5683179Z     mod = self._load_builtin("stdlib", module_name)
2023-01-12T18:23:44.5683724Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 630, in _load_builtin
2023-01-12T18:23:44.5684109Z     return self.load_module(mod, mod_ast=mod_ast)
2023-01-12T18:23:44.5684657Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 388, in load_module
2023-01-12T18:23:44.5685025Z     return self._process_module(mod_info, mod_ast)
2023-01-12T18:23:44.5685581Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 410, in _process_module
2023-01-12T18:23:44.5685996Z     module.ast = self._resolve_external_and_local_types(module.ast)
2023-01-12T18:23:44.5686625Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 363, in _resolve_external_and_local_types
2023-01-12T18:23:44.5687127Z     self._load_ast_dependencies(dependencies, lookup_ast)
2023-01-12T18:23:44.5687720Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 457, in _load_ast_dependencies
2023-01-12T18:23:44.5688108Z     dep_ast = self._try_import_prefix(name)
2023-01-12T18:23:44.5688658Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 437, in _try_import_prefix
2023-01-12T18:23:44.5689046Z     ast = self._import_module_by_name(prefix)
2023-01-12T18:23:44.5689607Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 680, in _import_module_by_name
2023-01-12T18:23:44.5690006Z     mod = self._load_builtin("stdlib", module_name)
2023-01-12T18:23:44.5690538Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 630, in _load_builtin
2023-01-12T18:23:44.5690927Z     return self.load_module(mod, mod_ast=mod_ast)
2023-01-12T18:23:44.5691465Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 388, in load_module
2023-01-12T18:23:44.5691849Z     return self._process_module(mod_info, mod_ast)
2023-01-12T18:23:44.5692401Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 410, in _process_module
2023-01-12T18:23:44.5692822Z     module.ast = self._resolve_external_and_local_types(module.ast)
2023-01-12T18:23:44.5693450Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 363, in _resolve_external_and_local_types
2023-01-12T18:23:44.5693875Z     self._load_ast_dependencies(dependencies, lookup_ast)
2023-01-12T18:23:44.5694458Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 455, in _load_ast_dependencies
2023-01-12T18:23:44.5694854Z     dep_ast = self._import_module_by_name(name)
2023-01-12T18:23:44.5695424Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 680, in _import_module_by_name
2023-01-12T18:23:44.5695806Z     mod = self._load_builtin("stdlib", module_name)
2023-01-12T18:23:44.5696348Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 630, in _load_builtin
2023-01-12T18:23:44.5696729Z     return self.load_module(mod, mod_ast=mod_ast)
2023-01-12T18:23:44.5697267Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 388, in load_module
2023-01-12T18:23:44.5697647Z     return self._process_module(mod_info, mod_ast)
2023-01-12T18:23:44.5698198Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 410, in _process_module
2023-01-12T18:23:44.5698677Z     module.ast = self._resolve_external_and_local_types(module.ast)
2023-01-12T18:23:44.5699314Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 363, in _resolve_external_and_local_types
2023-01-12T18:23:44.5699740Z     self._load_ast_dependencies(dependencies, lookup_ast)
2023-01-12T18:23:44.5700319Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 455, in _load_ast_dependencies
2023-01-12T18:23:44.5700711Z     dep_ast = self._import_module_by_name(name)
2023-01-12T18:23:44.5701264Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 680, in _import_module_by_name
2023-01-12T18:23:44.5701656Z     mod = self._load_builtin("stdlib", module_name)
2023-01-12T18:23:44.5702368Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 630, in _load_builtin
2023-01-12T18:23:44.5702760Z     return self.load_module(mod, mod_ast=mod_ast)
2023-01-12T18:23:44.5703303Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 388, in load_module
2023-01-12T18:23:44.5703752Z     return self._process_module(mod_info, mod_ast)
2023-01-12T18:23:44.5704316Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 410, in _process_module
2023-01-12T18:23:44.5704736Z     module.ast = self._resolve_external_and_local_types(module.ast)
2023-01-12T18:23:44.5705359Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 363, in _resolve_external_and_local_types
2023-01-12T18:23:44.5705788Z     self._load_ast_dependencies(dependencies, lookup_ast)
2023-01-12T18:23:44.5706375Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 455, in _load_ast_dependencies
2023-01-12T18:23:44.5706759Z     dep_ast = self._import_module_by_name(name)
2023-01-12T18:23:44.5707326Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 680, in _import_module_by_name
2023-01-12T18:23:44.5707718Z     mod = self._load_builtin("stdlib", module_name)
2023-01-12T18:23:44.5708265Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 630, in _load_builtin
2023-01-12T18:23:44.5708647Z     return self.load_module(mod, mod_ast=mod_ast)
2023-01-12T18:23:44.5709187Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 388, in load_module
2023-01-12T18:23:44.5709568Z     return self._process_module(mod_info, mod_ast)
2023-01-12T18:23:44.5710123Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 410, in _process_module
2023-01-12T18:23:44.5710540Z     module.ast = self._resolve_external_and_local_types(module.ast)
2023-01-12T18:23:44.5711164Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 363, in _resolve_external_and_local_types
2023-01-12T18:23:44.5711583Z     self._load_ast_dependencies(dependencies, lookup_ast)
2023-01-12T18:23:44.5712171Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 455, in _load_ast_dependencies
2023-01-12T18:23:44.5712560Z     dep_ast = self._import_module_by_name(name)
2023-01-12T18:23:44.5713122Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 680, in _import_module_by_name
2023-01-12T18:23:44.5713514Z     mod = self._load_builtin("stdlib", module_name)
2023-01-12T18:23:44.5714063Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 627, in _load_builtin
2023-01-12T18:23:44.5714480Z     filename, mod_ast = loader.load_module(namespace, module_name)
2023-01-12T18:23:44.5715065Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/imports/typeshed.py", line 454, in load_module
2023-01-12T18:23:44.5715578Z     ast = parser.parse_string(src, filename=filename, name=module_name,
2023-01-12T18:23:44.5716170Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/pyi/parser.py", line 792, in parse_string
2023-01-12T18:23:44.5716609Z     return parse_pyi(src, filename=filename, module_name=name, options=options)
2023-01-12T18:23:44.5717195Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/pyi/parser.py", line 807, in parse_pyi
2023-01-12T18:23:44.5717547Z     root = gen_pytd.visit(root)
2023-01-12T18:23:44.5718056Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/ast/visitor.py", line 31, in visit
2023-01-12T18:23:44.5718400Z     ret = self.visit(v)
2023-01-12T18:23:44.5718895Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/ast/visitor.py", line 40, in visit
2023-01-12T18:23:44.5719233Z     ret = self.visit(v)
2023-01-12T18:23:44.5719722Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/ast/visitor.py", line 34, in visit
2023-01-12T18:23:44.5720068Z     out = self._call_visitor(node)
2023-01-12T18:23:44.5720646Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/pyi/visitor.py", line 38, in _call_visitor
2023-01-12T18:23:44.5721119Z     raise ParseError.from_exc(e).at(node, self.filename, self.src_code)
2023-01-12T18:23:44.5721708Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/pyi/visitor.py", line 36, in _call_visitor
2023-01-12T18:23:44.5722066Z     return super()._call_visitor(node)
2023-01-12T18:23:44.5722600Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/ast/visitor.py", line 55, in _call_visitor
2023-01-12T18:23:44.5722954Z     return visitor(node)
2023-01-12T18:23:44.5723490Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/pyi/parser.py", line 376, in visit_FunctionDef
2023-01-12T18:23:44.5723870Z     self._preprocess_function(node)
2023-01-12T18:23:44.5724429Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/pyi/parser.py", line 370, in _preprocess_function
2023-01-12T18:23:44.5724825Z     node.args = self.convert_node(node.args)
2023-01-12T18:23:44.5725367Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/pyi/parser.py", line 315, in convert_node
2023-01-12T18:23:44.5725755Z     ret = self.annotation_visitor.visit(node)
2023-01-12T18:23:44.5726283Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/ast/visitor.py", line 31, in visit
2023-01-12T18:23:44.5726611Z     ret = self.visit(v)
2023-01-12T18:23:44.5727103Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/ast/visitor.py", line 40, in visit
2023-01-12T18:23:44.5727443Z     ret = self.visit(v)
2023-01-12T18:23:44.5727932Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/ast/visitor.py", line 34, in visit
2023-01-12T18:23:44.5728284Z     out = self._call_visitor(node)
2023-01-12T18:23:44.5728809Z   File "/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/pytype/pyi/visitor.py", line 38, in _call_visitor
2023-01-12T18:23:44.5729274Z     raise ParseError.from_exc(e).at(node, self.filename, self.src_code)
2023-01-12T18:23:44.5729713Z pytype.pyi.types.ParseError:   File: "/home/runner/work/typeshed/typeshed/stdlib/email/header.pyi", line 26
2023-01-12T18:23:44.5730073Z ParseError: list index out of range
```

</details>
The CI failure seems spurious, some package failed to download.

Resolving patch:
diff --git a/pytype/pyi/parser.py b/pytype/pyi/parser.py
--- a/pytype/pyi/parser.py
+++ b/pytype/pyi/parser.py
@@ -129,6 +129,16 @@ def _attribute_to_name(node: ast3.Attribute) -> ast3.Name:
 class AnnotationVisitor(visitor.BaseVisitor):
   """Converts typed_ast annotations to pytd."""
 
+  def __init__(self, *args, **kwargs):
+    super().__init__(*args, **kwargs)
+    # Exclude defaults because they may contain strings
+    # which should not be interpreted as annotations
+    self._node_children[self._ast.arguments] = [
+        field
+        for field in self._ast.arguments._fields
+        if field not in ("kw_defaults", "defaults")
+    ]
+
   def show(self, node):
     print(debug.dump(node, ast3, include_attributes=False))
 


Test patch:
diff --git a/pytype/pyi/parser_test.py b/pytype/pyi/parser_test.py
--- a/pytype/pyi/parser_test.py
+++ b/pytype/pyi/parser_test.py
@@ -576,9 +576,9 @@ class A: ...
 
   def test_def(self):
     self.check("""
-      def f(x: "int") -> "str": ...
+      def f(x: "int", *args: "float", y: "str", **kwargs: "bool") -> "str": ...
     """, """
-      def f(x: int) -> str: ...
+      def f(x: int, *args: float, y: str, **kwargs: bool) -> str: ...
     """)
 
 
@@ -846,6 +846,13 @@ def test_params(self):
     self.check("def foo(x: int, y: str, z: bool,) -> int: ...",
                "def foo(x: int, y: str, z: bool) -> int: ...")
 
+  def test_defaults(self):
+    self.check("""
+      def f(x: int = 3, y: str = " ") -> None: ...
+    """, """
+      def f(x: int = ..., y: str = ...) -> None: ...
+    """)
+
   def test_star_params(self):
     self.check("def foo(*, x) -> str: ...")
     self.check("def foo(x: int, *args) -> str: ...")