PY-20460 Fixed: typechecker false positive with slice

Update parameter type in str.__getitem__, bytes.__getitem__ (Py3) and unicode.__getitem__ (Py2) skeletons to receive slices
This commit is contained in:
Semyon Proshev
2016-09-09 16:55:55 +03:00
parent b698811721
commit ef22dc0793
7 changed files with 42 additions and 10 deletions

View File

@@ -1269,9 +1269,9 @@ class str(basestring):
return b''
def __getitem__(self, y):
"""y-th item of x, origin 0.
"""y-th item of x or substring, origin 0.
:type y: numbers.Integral
:type y: numbers.Integral | slice
:rtype: str
"""
return b''
@@ -1659,9 +1659,9 @@ class unicode(basestring):
return ''
def __getitem__(self, y):
"""y-th item of x, origin 0.
"""y-th item of x or substring, origin 0.
:type y: numbers.Integral
:type y: numbers.Integral | slice
:rtype: unicode
"""
return ''

View File

@@ -985,9 +985,9 @@ class bytes(object):
return b''
def __getitem__(self, y):
"""y-th item of x, origin 0.
"""y-th item of x or substring, origin 0.
:type y: numbers.Integral
:type y: numbers.Integral | slice
:rtype: int | bytes
"""
return 0
@@ -1359,9 +1359,9 @@ class str(object):
return ''
def __getitem__(self, y):
"""y-th item of x, origin 0.
"""y-th item of x or substring, origin 0.
:type y: numbers.Integral
:type y: numbers.Integral | slice
:rtype: str
"""
return ''

View File

@@ -0,0 +1,4 @@
sl = slice(0, 2)
st = b"abcdef"
print(st[sl])

View File

@@ -0,0 +1,4 @@
sl = slice(0, 2)
st = "abcdef"
print(st[sl])

View File

@@ -0,0 +1,4 @@
sl = slice(0, 2)
st = u"abcdef"
print(st[sl])

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -109,6 +109,16 @@ public class Py3TypeCheckerInspectionTest extends PyTestCase {
doTest();
}
// PY-20460
public void testStringGetItemWithSlice() {
doTest();
}
// PY-20460
public void testBytesGetItemWithSlice() {
doTest();
}
// PY-19796
public void testOrd() {
doTest();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -297,6 +297,16 @@ public class PyTypeCheckerInspectionTest extends PyTestCase {
doTest();
}
// PY-20460
public void testStringGetItemWithSlice() {
doTest();
}
// PY-20460
public void testUnicodeGetItemWithSlice() {
doTest();
}
// PY-19884
public void testAbsSetAndMutableSet() {
doTest();