Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#5364 defect closed fixed (fixed)

Avoid indexing ctypes.WinError objects

Reported by: Antoine Pitrou Owned by: Jean-Paul Calderone
Priority: normal Milestone: Python-3.x
Component: core Keywords:
Cc: Antoine Pitrou Branch:
Author:

Description (last modified by Jean-Paul Calderone)

Attaching patch, which replaces indexing with a lookup of the strerror attribute.

Attachments (3)

winerror.patch (485 bytes) - added by Antoine Pitrou 9 years ago.
winerror2.patch (1.2 KB) - added by Antoine Pitrou 9 years ago.
winerror3.patch (1.8 KB) - added by Antoine Pitrou 9 years ago.

Download all attachments as: .zip

Change History (13)

Changed 9 years ago by Antoine Pitrou

Attachment: winerror.patch added

comment:1 Changed 9 years ago by Antoine Pitrou

Cc: Antoine Pitrou added
Keywords: review added

comment:2 Changed 9 years ago by Jean-Paul Calderone

Description: modified (diff)

comment:3 Changed 9 years ago by Jean-Paul Calderone

Keywords: review removed
Owner: set to Antoine Pitrou

Thanks. Took me a few minutes to find the unit tests for this code, which turned out to be in twisted.test.test_strerror instead of twisted.python.test.test_win32. We should probably merge those two test modules.

The change seems somewhat sensible, but I get a test failure:

===============================================================================
[ERROR]
Traceback (most recent call last):
  File "/home/exarkun/Projects/Twisted/trunk/twisted/test/test_strerror.py", line 89, in test_winError
    message = formatter.formatError(self.probeErrorCode)
  File "/home/exarkun/Projects/Twisted/trunk/twisted/python/win32.py", line 159, in formatError
    return self.winError(errorcode).strerror
exceptions.AttributeError: 'tuple' object has no attribute 'strerror'

twisted.test.test_strerror.ErrorFormatingTestCase.test_winError
-------------------------------------------------------------------------------

(on either Linux or Windows). Looks like the tests need to be adjusted a bit as well. Thanks again.

comment:4 Changed 9 years ago by Antoine Pitrou

Cc: Antoine Pitrou removed
Keywords: review added

I am sorry, I hadn't run the test suite. Here is an updated patch fixing the tests (since I think passing a tuple here is bogus). Tested under Windows.

Changed 9 years ago by Antoine Pitrou

Attachment: winerror2.patch added

comment:5 Changed 9 years ago by Antoine Pitrou

Owner: Antoine Pitrou deleted

comment:6 Changed 9 years ago by Antoine Pitrou

Cc: Antoine Pitrou added

comment:7 Changed 9 years ago by Antoine Pitrou

New patch fixing additional instances of exception indexing in test_strerror itself (sorry, I was initially testing under 2.x).

Changed 9 years ago by Antoine Pitrou

Attachment: winerror3.patch added

comment:8 Changed 9 years ago by Jean-Paul Calderone

Keywords: review removed
Owner: set to Jean-Paul Calderone

Thanks. This looks good and passes tests here as well. I'll apply it.

comment:9 Changed 9 years ago by Jean-Paul Calderone

Resolution: fixed
Status: newclosed

(In [33091]) Use the strerror attribute of ctypes.WinError instead of indexing the exception object.

Author: antoine Reviewer: exarkun Fixes: #5364

Replace another usage of the deprecated exception indexing API with a named attribute of the exception object. In this case, the strerror attribute of the ctypes.WinError type.

comment:10 Changed 9 years ago by Jean-Paul Calderone

Summary: Avoid indexing WindowsError objectsAvoid indexing ctypes.WinError objects
Note: See TracTickets for help on using tickets.