| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| def g(self) -> None: pass | ||
| [out] | ||
| main:6: error: Return type of "f" incompatible with supertype "A" | ||
| main:7: error: Return type of "g" incompatible with supertype "A" |
There was a problem hiding this comment.
Why is this no longer an error?
Sorry, something went wrong.
There was a problem hiding this comment.
None is a subtype of A, so this is valid.
Sorry, something went wrong.
There was a problem hiding this comment.
Well, only without --strict-optional, or if the base class has -> Optional[A].
Sorry, something went wrong.
There was a problem hiding this comment.
Sure, but --strict-optional is still not enabled by default.
Sorry, something went wrong.
There was a problem hiding this comment.
Ah, I was confused by the PR title (and didn't read the whole thing).
Sorry, something went wrong.
There was a problem hiding this comment.
Nice! This simplifies things a lot and improves consistency.
Sorry, something went wrong.
| # Lambdas are allowed to have None returns. | ||
| # Functions returning a value of type None are allowed to have a None return. | ||
| if isinstance(self.scope.top_function(), FuncExpr) or isinstance(typ, NoneTyp): | ||
| if is_lambda or isinstance(typ, NoneTyp): |
There was a problem hiding this comment.
This is unclear.
Sorry, something went wrong.
There was a problem hiding this comment.
Added some comments
Sorry, something went wrong.
| def ff() -> None: | ||
| x = f() # E: Need type annotation for variable | ||
| x = f() | ||
| reveal_type(x) |
There was a problem hiding this comment.
There's no output from reveal_type. The desired behavior would probably be to require an annotation for x.
Sorry, something went wrong.
There was a problem hiding this comment.
Filed issue for this instead: #3032.
Sorry, something went wrong.
| def g(a: T) -> None: pass | ||
| [out] | ||
|
|
||
| [case testUnsolvableInferenceResult] |
There was a problem hiding this comment.
Consider enabling this test case and renaming it if the output doesn't correspond to the original intent of the test case.
Sorry, something went wrong.
There was a problem hiding this comment.
This is a test involving void and is no longer relevant. It no longer tests anything interesting that is untested elsewhere.
Sorry, something went wrong.
| a = x | ||
|
|
||
| for y in []: # E: Need type annotation for variable | ||
| for y in []: |
There was a problem hiding this comment.
What's the type of y here? I think that the original message was fine. At least add a reveal_type.
Sorry, something went wrong.
There was a problem hiding this comment.
y is inferred as None. Added a reveal_type.
Sorry, something went wrong.
| a = y | ||
|
|
||
| for e, f in [[]]: # E: Need type annotation for variable | ||
| for e, f in [[]]: |
There was a problem hiding this comment.
Similar to above; at least add reveal_types.
Sorry, something went wrong.
There was a problem hiding this comment.
Done.
Sorry, something went wrong.
|
|
||
| [case testPartiallyInitializedToNoneAndThenToIncompleteType] | ||
| [case testPartiallyInitializedToNoneAndThenToIncompleteType-skip] | ||
| # TODO(ddfisher): fix partial type bug and re-enable |
There was a problem hiding this comment.
Add an issue for this so that we won't lose track of it.
Sorry, something went wrong.
There was a problem hiding this comment.
Sorry, something went wrong.
| def test() -> 'Generator[Any, None, None]': | ||
| yield from greet() | ||
| x = yield from greet() # Error | ||
| x = yield from greet() |
There was a problem hiding this comment.
For consistency, we should retain the original error message (... does not return a value).
Sorry, something went wrong.
There was a problem hiding this comment.
Done.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
After this lands, per-file strict Optional should be straightforward. This should fix a lot of bugs around None. Introduces a small bug with partial types (where mypy is overly permissive) which will be fixed in a follow up PR.