-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More concise formatting for dummy implementations (#3796)
- Loading branch information
1 parent
59e8936
commit c160e4b
Showing
7 changed files
with
135 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
from typing import NoReturn, Protocol, Union, overload | ||
|
||
|
||
def dummy(a): ... | ||
def other(b): ... | ||
|
||
|
||
@overload | ||
def a(arg: int) -> int: ... | ||
@overload | ||
def a(arg: str) -> str: ... | ||
@overload | ||
def a(arg: object) -> NoReturn: ... | ||
def a(arg: Union[int, str, object]) -> Union[int, str]: | ||
if not isinstance(arg, (int, str)): | ||
raise TypeError | ||
return arg | ||
|
||
class Proto(Protocol): | ||
def foo(self, a: int) -> int: | ||
... | ||
|
||
def bar(self, b: str) -> str: ... | ||
def baz(self, c: bytes) -> str: | ||
... | ||
|
||
|
||
def dummy_two(): | ||
... | ||
@dummy | ||
def dummy_three(): | ||
... | ||
|
||
def dummy_four(): | ||
... | ||
|
||
@overload | ||
def b(arg: int) -> int: ... | ||
|
||
@overload | ||
def b(arg: str) -> str: ... | ||
@overload | ||
def b(arg: object) -> NoReturn: ... | ||
|
||
def b(arg: Union[int, str, object]) -> Union[int, str]: | ||
if not isinstance(arg, (int, str)): | ||
raise TypeError | ||
return arg | ||
|
||
# output | ||
|
||
from typing import NoReturn, Protocol, Union, overload | ||
|
||
|
||
def dummy(a): ... | ||
def other(b): ... | ||
|
||
|
||
@overload | ||
def a(arg: int) -> int: ... | ||
@overload | ||
def a(arg: str) -> str: ... | ||
@overload | ||
def a(arg: object) -> NoReturn: ... | ||
def a(arg: Union[int, str, object]) -> Union[int, str]: | ||
if not isinstance(arg, (int, str)): | ||
raise TypeError | ||
return arg | ||
|
||
|
||
class Proto(Protocol): | ||
def foo(self, a: int) -> int: ... | ||
|
||
def bar(self, b: str) -> str: ... | ||
def baz(self, c: bytes) -> str: ... | ||
|
||
|
||
def dummy_two(): ... | ||
@dummy | ||
def dummy_three(): ... | ||
|
||
|
||
def dummy_four(): ... | ||
|
||
|
||
@overload | ||
def b(arg: int) -> int: ... | ||
|
||
|
||
@overload | ||
def b(arg: str) -> str: ... | ||
@overload | ||
def b(arg: object) -> NoReturn: ... | ||
|
||
|
||
def b(arg: Union[int, str, object]) -> Union[int, str]: | ||
if not isinstance(arg, (int, str)): | ||
raise TypeError | ||
return arg |