[3.6] bpo-19903: IDLE: Calltips changed to use inspect.signature (GH-… · python/cpython@646f6c3 (original) (raw)

`@@ -46,25 +46,37 @@ def test_builtins(self):

`

46

46

``

47

47

`# Python class that inherits builtin methods

`

48

48

`class List(list): "List() doc"

`

``

49

+

49

50

`# Simulate builtin with no docstring for default tip test

`

50

51

`class SB: call = None

`

51

52

``

52

53

`def gtest(obj, out):

`

53

54

`self.assertEqual(signature(obj), out)

`

54

55

``

55

56

`if List.doc is not None:

`

56

``

`-

gtest(List, List.doc)

`

``

57

`+

gtest(List, List.doc) # This and append_doc changed in 3.7.

`

57

58

`gtest(list.new,

`

58

``

`-

'Create and return a new object. See help(type) for accurate signature.')

`

``

59

`+

'(*args, **kwargs)\nCreate and return a new object.'

`

``

60

`+

' See help(type) for accurate signature.')

`

59

61

`gtest(list.init,

`

``

62

`+

'(self, /, *args, **kwargs)' + ct._argument_positional + '\n' +

`

60

63

`'Initialize self. See help(type(self)) for accurate signature.')

`

61

``

`-

append_doc = "L.append(object) -> None -- append object to end" #see3.7

`

``

64

+

``

65

`+

append_doc = "L.append(object) -> None -- append object to end"

`

62

66

`gtest(list.append, append_doc)

`

63

67

`gtest([].append, append_doc)

`

64

68

`gtest(List.append, append_doc)

`

65

69

``

66

70

`gtest(types.MethodType, "method(function, instance)")

`

67

71

`gtest(SB(), default_tip)

`

``

72

`+

import re

`

``

73

`+

p = re.compile('')

`

``

74

`+

gtest(re.sub, '''(pattern, repl, string, count=0, flags=0)\nReturn the string obtained by replacing the leftmost

`

``

75

`+

non-overlapping occurrences of the pattern in string by the

`

``

76

`+

replacement repl. repl can be either a string or a callable;

`

``

77

`+

if a string, backslash escapes in it are processed. If it is

`

``

78

`+

a callable, it's passed the match object and must return''')

`

``

79

`+

gtest(p.sub, '''(repl, string, count=0)\nReturn the string obtained by replacing the leftmost non-overlapping occurrences o...''')

`

68

80

``

69

81

`def test_signature_wrap(self):

`

70

82

`if textwrap.TextWrapper.doc is not None:

`

`@@ -132,12 +144,20 @@ def test_starred_parameter(self):

`

132

144

`# test that starred first parameter is not removed from argspec

`

133

145

`class C:

`

134

146

`def m1(*args): pass

`

135

``

`-

def m2(**kwds): pass

`

136

147

`c = C()

`

137

``

`-

for meth, mtip in ((C.m1, '(*args)'), (c.m1, "(*args)"),

`

138

``

`-

(C.m2, "(**kwds)"), (c.m2, "(**kwds)"),):

`

``

148

`+

for meth, mtip in ((C.m1, '(*args)'), (c.m1, "(*args)"),):

`

139

149

`self.assertEqual(signature(meth), mtip)

`

140

150

``

``

151

`+

def test_invalid_method_signature(self):

`

``

152

`+

class C:

`

``

153

`+

def m2(**kwargs): pass

`

``

154

`+

class Test:

`

``

155

`+

def call(*, a): pass

`

``

156

+

``

157

`+

mtip = ct._invalid_method

`

``

158

`+

self.assertEqual(signature(C().m2), mtip)

`

``

159

`+

self.assertEqual(signature(Test()), mtip)

`

``

160

+

141

161

`def test_non_ascii_name(self):

`

142

162

`# test that re works to delete a first parameter name that

`

143

163

`# includes non-ascii chars, such as various forms of A.

`

`@@ -156,17 +176,23 @@ def test_attribute_exception(self):

`

156

176

`class NoCall:

`

157

177

`def getattr(self, name):

`

158

178

`raise BaseException

`

159

``

`-

class Call(NoCall):

`

``

179

`+

class CallA(NoCall):

`

``

180

`+

def call(oui, a, b, c):

`

``

181

`+

pass

`

``

182

`+

class CallB(NoCall):

`

160

183

`def call(self, ci):

`

161

184

`pass

`

162

``

`-

for meth, mtip in ((NoCall, default_tip), (Call, default_tip),

`

163

``

`-

(NoCall(), ''), (Call(), '(ci)')):

`

``

185

+

``

186

`+

for meth, mtip in ((NoCall, default_tip), (CallA, default_tip),

`

``

187

`+

(NoCall(), ''), (CallA(), '(a, b, c)'),

`

``

188

`+

(CallB(), '(ci)')):

`

164

189

`self.assertEqual(signature(meth), mtip)

`

165

190

``

166

191

`def test_non_callables(self):

`

167

192

`for obj in (0, 0.0, '0', b'0', [], {}):

`

168

193

`self.assertEqual(signature(obj), '')

`

169

194

``

``

195

+

170

196

`class Get_entityTest(unittest.TestCase):

`

171

197

`def test_bad_entity(self):

`

172

198

`self.assertIsNone(ct.get_entity('1/0'))

`