Skip to content

Commit 266040f

Browse files
committed
Revert "remove specific for Optional"
This reverts commit 61f6a59.
1 parent 61f6a59 commit 266040f

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

mypy/stubgen.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,10 @@ def get_str_type_of_node(self, rvalue: Node) -> str:
513513
return 'int'
514514
if isinstance(rvalue, NameExpr) and rvalue.name in ('True', 'False'):
515515
return 'bool'
516+
if isinstance(rvalue, NameExpr) and rvalue.name == 'None':
517+
self.add_typing_import('Optional')
518+
self.add_typing_import('Any')
519+
return 'Optional[Any]'
516520
self.add_typing_import('Any')
517521
return 'Any'
518522

test-data/unit/stubgen.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def g(b: int = ..., c: int = ...): ...
2626
[case testDefaultArgNone]
2727
def f(x=None): ...
2828
[out]
29-
from typing import Any
29+
from typing import Any, Optional
3030

31-
def f(x: Any = ...): ...
31+
def f(x: Optional[Any] = ...): ...
3232

3333
[case testDefaultArgBool]
3434
def f(x=True, y=False): ...

0 commit comments

Comments
 (0)