", line 1, in ? with File "", line 1, in (cherry picked from commit 8856940cf2e82cb17db2b684cd5732fe658605ca)">

[3.6] bpo-28315: Improve code examples in docs (GH-1372) (#1445) · python/cpython@af71364 (original) (raw)

`@@ -97,7 +97,7 @@ Functions are accessed as attributes of dll objects::

`

97

97

` <_FuncPtr object at 0x...>

`

98

98

` >>> print(windll.kernel32.MyOwnFunction) # doctest: +WINDOWS

`

99

99

` Traceback (most recent call last):

`

100

``

`-

File "", line 1, in ?

`

``

100

`+

File "", line 1, in

`

101

101

` File "ctypes.py", line 239, in getattr

`

102

102

` func = _StdcallFuncPtr(name, self)

`

103

103

` AttributeError: function 'MyOwnFunction' not found

`

`@@ -135,7 +135,7 @@ functions can be accessed by indexing the dll object with the ordinal number::

`

135

135

` <_FuncPtr object at 0x...>

`

136

136

` >>> cdll.kernel32[0] # doctest: +WINDOWS

`

137

137

` Traceback (most recent call last):

`

138

``

`-

File "", line 1, in ?

`

``

138

`+

File "", line 1, in

`

139

139

` File "ctypes.py", line 310, in getitem

`

140

140

` func = _StdcallFuncPtr(name, self)

`

141

141

` AttributeError: function ordinal 0 not found

`

`@@ -168,11 +168,11 @@ although an error is raised the function has been called::

`

168

168

``

169

169

` >>> windll.kernel32.GetModuleHandleA() # doctest: +WINDOWS

`

170

170

` Traceback (most recent call last):

`

171

``

`-

File "", line 1, in ?

`

``

171

`+

File "", line 1, in

`

172

172

` ValueError: Procedure probably called with not enough arguments (4 bytes missing)

`

173

173

` >>> windll.kernel32.GetModuleHandleA(0, 0) # doctest: +WINDOWS

`

174

174

` Traceback (most recent call last):

`

175

``

`-

File "", line 1, in ?

`

``

175

`+

File "", line 1, in

`

176

176

` ValueError: Procedure probably called with too many arguments (4 bytes in excess)

`

177

177

` >>>

`

178

178

``

``` @@ -181,13 +181,13 @@ The same exception is raised when you call an stdcall function with the

```

181

181

``

182

182

` >>> cdll.kernel32.GetModuleHandleA(None) # doctest: +WINDOWS

`

183

183

` Traceback (most recent call last):

`

184

``

`-

File "", line 1, in ?

`

``

184

`+

File "", line 1, in

`

185

185

` ValueError: Procedure probably called with not enough arguments (4 bytes missing)

`

186

186

` >>>

`

187

187

``

188

188

` >>> windll.msvcrt.printf(b"spam") # doctest: +WINDOWS

`

189

189

` Traceback (most recent call last):

`

190

``

`-

File "", line 1, in ?

`

``

190

`+

File "", line 1, in

`

191

191

` ValueError: Procedure probably called with too many arguments (4 bytes in excess)

`

192

192

` >>>

`

193

193

``

`@@ -200,7 +200,7 @@ argument values::

`

200

200

``

201

201

` >>> windll.kernel32.GetModuleHandleA(32) # doctest: +WINDOWS

`

202

202

` Traceback (most recent call last):

`

203

``

`-

File "", line 1, in ?

`

``

203

`+

File "", line 1, in

`

204

204

` OSError: exception: access violation reading 0x00000020

`

205

205

` >>>

`

206

206

``

`@@ -373,7 +373,7 @@ from within IDLE or PythonWin::

`

373

373

` 19

`

374

374

` >>> printf(b"%f bottles of beer\n", 42.5)

`

375

375

` Traceback (most recent call last):

`

376

``

`-

File "", line 1, in ?

`

``

376

`+

File "", line 1, in

`

377

377

` ArgumentError: argument 2: exceptions.TypeError: Don't know how to convert parameter 2

`

378

378

` >>>

`

379

379

``

`@@ -436,7 +436,7 @@ prototype for a C function), and tries to convert the arguments to valid types::

`

436

436

``

437

437

` >>> printf(b"%d %d %d", 1, 2, 3)

`

438

438

` Traceback (most recent call last):

`

439

``

`-

File "", line 1, in ?

`

``

439

`+

File "", line 1, in

`

440

440

` ArgumentError: argument 2: exceptions.TypeError: wrong type

`

441

441

` >>> printf(b"%s %d %f\n", b"X", 2, 3)

`

442

442

` X 2 3.000000

`

`@@ -486,7 +486,7 @@ single character Python bytes object into a C char::

`

486

486

` 'def'

`

487

487

` >>> strchr(b"abcdef", b"def")

`

488

488

` Traceback (most recent call last):

`

489

``

`-

File "", line 1, in ?

`

``

489

`+

File "", line 1, in

`

490

490

` ArgumentError: argument 2: exceptions.TypeError: one character string expected

`

491

491

` >>> print(strchr(b"abcdef", b"x"))

`

492

492

` None

`

`@@ -512,7 +512,7 @@ useful to check for error return values and automatically raise an exception::

`

512

512

` 486539264

`

513

513

` >>> GetModuleHandle("something silly") # doctest: +WINDOWS

`

514

514

` Traceback (most recent call last):

`

515

``

`-

File "", line 1, in ?

`

``

515

`+

File "", line 1, in

`

516

516

` File "", line 3, in ValidHandle

`

517

517

` OSError: [Errno 126] The specified module could not be found.

`

518

518

` >>>

`

`@@ -583,7 +583,7 @@ Here is a simple example of a POINT structure, which contains two integers named

`

583

583

` 0 5

`

584

584

` >>> POINT(1, 2, 3)

`

585

585

` Traceback (most recent call last):

`

586

``

`-

File "", line 1, in ?

`

``

586

`+

File "", line 1, in

`

587

587

` ValueError: too many initializers

`

588

588

` >>>

`

589

589

``

`@@ -786,7 +786,7 @@ new type::

`

786

786

` <class 'ctypes.LP_c_long'>

`

787

787

` >>> PI(42)

`

788

788

` Traceback (most recent call last):

`

789

``

`-

File "", line 1, in ?

`

``

789

`+

File "", line 1, in

`

790

790

` TypeError: expected c_long instead of int

`

791

791

` >>> PI(c_int(42))

`

792

792

` <ctypes.LP_c_long object at 0x...>

`

`@@ -862,7 +862,7 @@ but not instances of other types::

`

862

862

``

863

863

` >>> bar.values = (c_byte * 4)()

`

864

864

` Traceback (most recent call last):

`

865

``

`-

File "", line 1, in ?

`

``

865

`+

File "", line 1, in

`

866

866

` TypeError: incompatible types, c_byte_Array_4 instance instead of LP_c_long instance

`

867

867

` >>>

`

868

868

``

`@@ -913,7 +913,7 @@ work::

`

913

913

` ... ("next", POINTER(cell))]

`

914

914

` ...

`

915

915

` Traceback (most recent call last):

`

916

``

`-

File "", line 1, in ?

`

``

916

`+

File "", line 1, in

`

917

917

` File "", line 2, in cell

`

918

918

` NameError: name 'cell' is not defined

`

919

919

` >>>

`