Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add extra test cases
  • Loading branch information
ilinum committed Jun 21, 2017
commit 3b7a079d189cf82da3318d20b99eb8d7e0a68b7e
30 changes: 29 additions & 1 deletion test-data/unit/check-flags.test
Original file line number Diff line number Diff line change
Expand Up @@ -578,12 +578,16 @@ from typing import Callable, Any, List

def d(f) -> Callable[[int, Any], Any]: pass
def d2(f) -> Callable[[int], List[Any]]: pass

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be good to also test a callable which doesn't have Any as part of its return value.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was unclear. The test you added is good, but it'd also be worth testing a Callable that contains Any but not as part of its return value. (It looks to me like this case is currently not covered by any of the tests.)

@ilinum ilinum Jun 21, 2017 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right, this should be good now.
Test with Callable that takes parameters of type Any but returns something that's not Any.

def d3(f) -> Callable[[int], List[str]]: pass

@d
def f(i: int, s: str) -> None: # E: Type of decorated function contains type "Any" (Callable[[int, Any], Any])
pass
@d2
def g(i: int) -> None: # E: Type of decorated function contains type "Any" (Callable[[int], List[Any]])
def g(i: int) -> None: # E: Type of decorated function contains type "Any" (Callable[[int], List[Any]])
pass
@d3
def h(i: int) -> None: # no error
pass
[builtins fixtures/list.pyi]

Expand All @@ -608,6 +612,30 @@ def d(p) -> int:
def f(i):
return i

[case testDisallowAnyDecoratedUntypedUndecoratedFunction]
# flags: --disallow-any=decorated
from typing import Callable

def f(i): # no error
return i

[case testDisallowAnyDecoratedTwoDecorators]
# flags: --disallow-any=decorated
from typing import Callable

def typed_dec(f) -> Callable[[], int]: pass
def untyped_dec(f): pass

@typed_dec
@untyped_dec
def f(): # no error
return i

@untyped_dec
@typed_dec
def g(): # E: Function is untyped after decorator transformation
return i

[case testDisallowAnyExprSimple]
# flags: --disallow-any=expr
from typing import Any
Expand Down