Opened 2 years ago

Last modified 22 months ago

#5789 task new

Remove usage of UserDict

Reported by: thijs Owned by: vperic
Priority: lowest Milestone: Python-3.x
Component: core Keywords: py3k
Cc: thijs Branch:
Author: Launchpad Bug:

Description (last modified by thijs)

Remove usage of UserDict once Python 2.6 support is dropped completely (or manhole.explorer or protocols.postfix are ported to python 3).

twisted/protocols/postfix.py:import UserDict
twisted/protocols/postfix.py: UserDict.UserDict):
twisted/manhole/explorer.py:import UserDict
twisted/manhole/explorer.py:class Pool(UserDict.UserDict):

Attachments (1)

userdict.patch (3.0 KB) - added by vperic 2 years ago.
Remove UserDict

Download all attachments as: .zip

Change History (8)

comment:1 Changed 2 years ago by therve

Note that UserDict isn't in the collections module in 2.X. Regarding DictMixin, you should be able to use MutableMapping with some adjustement.

comment:2 Changed 2 years ago by thijs

  • Description modified (diff)
  • Summary changed from Replace UserDict imports with collections version to Replace usage of UserDict with twisted.python.compat version

Meh, not sure why I didnt notice that before. So in Python 2.7 it's in the old place and Python 3 moves it to the collections module. I suggest to add a twisted.python.compat version in that case like we did with execfile.

comment:3 Changed 2 years ago by antoine

In many cases, UserDict is replaceable with dict, which is better than importing some crufty compatibility code. I would suggest trying each case separately.

Changed 2 years ago by vperic

Remove UserDict

comment:4 Changed 2 years ago by vperic

  • Keywords review py3k added
  • Summary changed from Replace usage of UserDict with twisted.python.compat version to Remove usage of UserDict

Attached patch takes care of UserDict, by inheriting directly from dict. It's a very small patch, but this is kinda low-level so smaller is better; I'm going to open a separate ticket for replacing DictMixin with MutableMapping (I almost have a patch, but it's a different change again and smaller is better). The changes here should be ok - all the touched lines are tested and all tests pass.

In lieu of what this ticket actually does, I'll change the summary to just "Remove usage of UserDict"

comment:5 Changed 2 years ago by thijs

  • Keywords review removed
  • Owner set to vperic

Thanks for working on this. Most changes are indeed covered by tests.

  • twisted.protocols.postfix the docstring """A dict that preserves insert order whenever possible.""" should be on 3 lines
  • Same for """A dict that preserves insert order whenever possible.""" in twisted.python.util
  • It's missing a .removal newsfile
  • There are 3 lines not covered for OrderedDict and since you're changing it's class it would be good to have tests for those lines (copy and iterkeys) as well for peace of mind.

Can you put the patch in a branch as well so we can buildbot test it?

comment:6 Changed 2 years ago by vperic

1, 2: will do
3: Why .removal? No features are getting removed here, I wouldn't give it more than a .misc personally.
4: Ah, I really don't feel like doing this, in part because those tests themselves probably also need cleanup and I don't feel like doing that. As it stands, all the changes *are* tested and the ticket does what it says it does. Still, if you want to insist on this, I guess I'll have to do it. :)

comment:7 Changed 22 months ago by thijs

  • Description modified (diff)
  • Priority changed from normal to lowest
  • during the python 3 port (r36719) OrderedDict in python.util changed it's base class from UserDict to object for python 3 only.
  • usage of DictMixin in http_headers was removed during the python 3 port.
  • the following classes still use UserDict (excluding python.util):
    twisted/protocols/postfix.py:import UserDict
    twisted/protocols/postfix.py: UserDict.UserDict):
    twisted/manhole/explorer.py:import UserDict
    twisted/manhole/explorer.py:class Pool(UserDict.UserDict):
    

I suggest we remove usage of UserDict once Python 2.6 support is dropped or python 3 support is added for manhole.explorer or protocols.postfix. Updating the ticket description and priority.

Note: See TracTickets for help on using tickets.