-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Dmypy 418 #18942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dmypy 418 #18942
Changes from 6 commits
7ecb077
b61c9ba
3ff8f89
6b08c08
3930148
4b1d260
615f869
06f6b73
84e9bba
aad7793
ee5f4b9
2b38551
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [mypy] | ||
| check_untyped_defs = true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,7 +74,6 @@ | |
| TypeOfAny, | ||
| TypeStrVisitor, | ||
| TypeTranslator, | ||
| TypeVarType, | ||
| UninhabitedType, | ||
| UnionType, | ||
| get_proper_type, | ||
|
|
@@ -653,7 +652,7 @@ def extract_from_decorator(self, node: Decorator) -> FuncDef | None: | |
| for ct in typ.items: | ||
| if not ( | ||
| len(ct.arg_types) == 1 | ||
| and isinstance(ct.arg_types[0], TypeVarType) | ||
| # and isinstance(ct.arg_types[0], TypeVarType) | ||
| and ct.arg_types[0] == ct.ret_type | ||
| ): | ||
| return None | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is looks like a special case for this decorator: def f(x: T) -> T:
return xyou should add a special case in addition to this.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, technically this line is limiting to that special case. And this will even fix the linked issue, two callables of that shape will compare equal AFAIC. But this also makes the following (completely wrong) deco generate a signature: def deco(fn: str) -> str: ...
@deco
def foo():
print()So I agree there should be one more special case, not just blanket "one-arg function returning its arg unchanged". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would argue that any identity function should be fine here -- if that decorator happens to have the wrong types that's not really this code's problem (it's just trying to unwrap the underlying callable) and I suspect there's many many ways to type an identity function with varying specificity making this particular condition difficult-to-impossible to write |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| from typing import Callable, TypeVar | ||
| from typing_extensions import ParamSpec | ||
|
|
||
| R = TypeVar("R") | ||
| P = ParamSpec("P") | ||
|
|
||
|
|
||
| def dec(f: Callable[P, R]) -> Callable[P, R]: | ||
| return f | ||
|
|
||
|
|
||
| @dec | ||
| def f() -> None: | ||
| print("hello world") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is talking about importing
typingand this isn't the convention.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the convention is "never alias-import stdlib modules unless strictly necessary". Please revert this doc change along with all imports garbled in other files.