-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix None slice bounds with strict-optional #3445
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
Conversation
@@ -998,6 +998,7 @@ a[:o] # E: Slice index must be an integer or None | |||
[builtins fixtures/slice.pyi] | |||
|
|||
[case testNoneSliceBounds] | |||
# flags: --strict-optional |
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.
We should probably test this both with and without strict-optional.
mypy/checkexpr.py
Outdated
@@ -1893,10 +1893,11 @@ def analyze_super(self, e: SuperExpr, is_lvalue: bool) -> Type: | |||
return AnyType() | |||
|
|||
def visit_slice_expr(self, e: SliceExpr) -> Type: | |||
expected = UnionType.make_union([NoneTyp(), self.named_type('builtins.int')]) |
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.
Should probably use typeanal.make_optional_type()
instead.
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.
I was looking for such function/method, but couldn't find it. Thanks!
Thanks! |
* master: (23 commits) Make return type of open() more precise (python#3477) Add test cases that delete a file during incremental checking (python#3461) Parse each format-string component separately (python#3390) Don't warn about returning Any if it is a proper subtype of the return type (python#3473) Add __setattr__ support (python#3451) Remove bundled lib-typing (python#3337) Move version of extensions to post-release (python#3348) Fix None slice bounds with strict-optional (python#3445) Allow NewType subclassing NewType. (python#3465) Add console scripts (python#3074) Fix 'variance' label. Change label for variance section to just 'variance' (python#3429) Better error message for invalid package names passed to mypy (python#3447) Fix last character cut in html-report if file does not end with newline (python#3466) Print pytest output as it happens (python#3463) Add mypy roadmap (python#3460) Add flag to avoid interpreting arguments with a default of None as Optional (python#3248) Add type checking plugin support for functions (python#3299) Mismatch of inferred type and return type note (python#3428) Sync typeshed (python#3449) ...
Fixes #3442.