Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write UserDict fixer for 2to3 #47125

Closed
brettcannon opened this issue May 16, 2008 · 30 comments
Closed

Write UserDict fixer for 2to3 #47125

brettcannon opened this issue May 16, 2008 · 30 comments
Assignees
Labels
topic-2to3 type-bug An unexpected behavior, bug, or error

Comments

@brettcannon
Copy link
Member

BPO 2876
Nosy @loewis, @brettcannon, @rhettinger, @benjaminp, @ashemedai, @merwok, @bitdancer
Files
  • fix_userdict.diff: UserDict fixer and test suite
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/benjaminp'
    closed_at = <Date 2012-07-02.19:26:26.706>
    created_at = <Date 2008-05-16.04:49:07.804>
    labels = ['type-bug', 'expert-2to3']
    title = 'Write UserDict fixer for 2to3'
    updated_at = <Date 2012-07-02.19:26:26.705>
    user = 'https://github.com/brettcannon'

    bugs.python.org fields:

    activity = <Date 2012-07-02.19:26:26.705>
    actor = 'brett.cannon'
    assignee = 'benjamin.peterson'
    closed = True
    closed_date = <Date 2012-07-02.19:26:26.706>
    closer = 'brett.cannon'
    components = ['2to3 (2.x to 3.x conversion tool)']
    creation = <Date 2008-05-16.04:49:07.804>
    creator = 'brett.cannon'
    dependencies = []
    files = ['11634']
    hgrepos = []
    issue_num = 2876
    keywords = ['patch']
    message_count = 30.0
    messages = ['66900', '66904', '67089', '67090', '67100', '67101', '67357', '67361', '67378', '68248', '69112', '71354', '71355', '71378', '71650', '71667', '71669', '71891', '71903', '72970', '73347', '73915', '73933', '74107', '74278', '74279', '102620', '102623', '102624', '164532']
    nosy_count = 9.0
    nosy_names = ['loewis', 'brett.cannon', 'collinwinter', 'rhettinger', 'benjamin.peterson', 'asmodai', 'nedds', 'eric.araujo', 'r.david.murray']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue2876'
    versions = ['Python 2.6']

    @brettcannon
    Copy link
    Member Author

    In Python 3.0, the UserDict module was removed and the UserDict class was
    moved to the collections module. That change-over needs to be backported
    to 2.6 so that the UserDict module can be deprecated.

    @brettcannon brettcannon added release-blocker stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels May 16, 2008
    @rhettinger
    Copy link
    Contributor

    This doesn't make any sense to me. The 2.6 code runs fine as-is. The
    2-to-3 tool can handle switching from UserDict.UserDict to
    collections.UserDict. What's the issue? And why is this marked as a
    release blocker?

    @brettcannon
    Copy link
    Member Author

    You only kept the UserDict class, right? Well, that means you need to
    deprecate DictMixin and any other classes in that module.

    @brettcannon
    Copy link
    Member Author

    And it is a release blocker as we are trying to get all deprecations into
    b1.

    @rhettinger
    Copy link
    Contributor

    The DictMixin class gets renamed to collections.MutableMapping. So, it
    is just another 2-to-3 converter job.

    @brettcannon
    Copy link
    Member Author

    The that needs to be added to 2to3.

    @brettcannon brettcannon reopened this May 20, 2008
    @brettcannon brettcannon changed the title Backport UserDict move in 3.0 Write UserDict fixer for 2to3 May 20, 2008
    @brettcannon
    Copy link
    Member Author

    Raymond, can you tell me exactly where each module-level thing in UserDict
    went and if it was renamed or not? That way the fixer can get written.

    @rhettinger
    Copy link
    Contributor

    UserDict.UserDict is gone.
    UserDict.IterableUserDict class is now collections.UserDict.
    UserDict.Mixin is now collections.MutableMapping.

    The new classes comform to the new dict API, so they fixer needs to
    also make same method adaptatations as for dicts (i.e. d.keys() --> list
    (d.keys() and d.has_key --> d.__contains__).

    @rhettinger rhettinger assigned brettcannon and unassigned rhettinger May 26, 2008
    @brettcannon
    Copy link
    Member Author

    I don't know if 2to3 can handle the class renames. Up to this point we
    have only been handling module renames.

    Collin, how doable is this?

    @collinwinter
    Copy link
    Mannequin

    collinwinter mannequin commented Jun 15, 2008

    It's doable, but there's no existing support similar to what fix_imports
    provides.

    I won't have time to work on this for the foreseeable future, but if
    someone is interested in working on this, I'd add this challenge:
    implement this in a way that generalizes well and is better/easier than
    what fix_imports does. I never expected fix_imports's mechanism to be so
    heavily reused, and as a result it's ass-slow.

    @brettcannon
    Copy link
    Member Author

    There is a possible patch in bpo-2046.

    @nedds
    Copy link
    Mannequin

    nedds mannequin commented Aug 18, 2008

    What's the current status of this? If nobody is working on it, I would
    be willing to give it a shot. Can somebody just confirm that I have a
    correct understanding of the problem.
    UserDict.UserDict needs a deprecation warning, UserDict.IterableUserDict
    becomes collections.UserDict, and UserDict.Mixin becomes
    collections.MutableMapping. Then for keys(), items(), and values(), I
    want to replace something like d.keys() to list(d.keys()).
    One added question: based on what I gathered from PEP-3106, this last
    part is only needed in a situation such as a = d.keys(), but not a
    situation like for key in keys:, so because in the later case wrapping
    the call to keys() in list() would presumably be suboptimal, is this
    something I should try and avoid? I'm not sure exactly how it could be
    done, but I have some idea of how it to do it.

    @brettcannon
    Copy link
    Member Author

    On Mon, Aug 18, 2008 at 10:59 AM, Nick Edds <report@bugs.python.org> wrote:

    Nick Edds <nedds@uchicago.edu> added the comment:

    What's the current status of this?

    I think it is waiting for someone to work on it.

    If nobody is working on it, I would
    be willing to give it a shot.

    Great!

    Can somebody just confirm that I have a
    correct understanding of the problem.
    UserDict.UserDict needs a deprecation warning, UserDict.IterableUserDict
    becomes collections.UserDict, and UserDict.Mixin becomes
    collections.MutableMapping.

    In theory, yes, but the superclasses have changed, so I don't know if
    having a fixer is really the best option in this case since it is not
    a simple renaming. Perhaps deprecation warnings stating that the
    classes have been moved and given different superclasses would make
    more sense?

    Then for keys(), items(), and values(), I
    want to replace something like d.keys() to list(d.keys()).

    Sure, but how the heck are you going to get 2to3 to do this properly
    just for UserDict instances? Doesn't the keys()/values()/items() fixer
    already do this blindly anyway?

    One added question: based on what I gathered from PEP-3106, this last
    part is only needed in a situation such as a = d.keys(), but not a
    situation like for key in keys:, so because in the later case wrapping
    the call to keys() in list() would presumably be suboptimal, is this
    something I should try and avoid? I'm not sure exactly how it could be
    done, but I have some idea of how it to do it.

    Yes, you are right that wrapping the call in a for loop is not needed
    since code will never come across it. But as I said above, doesn't the
    fixer for dicts already handle all of this?

    @nedds
    Copy link
    Mannequin

    nedds mannequin commented Aug 18, 2008

    Ahh right. I totally forgot that there was already a fix_dict.py that
    took care of that.

    @nedds
    Copy link
    Mannequin

    nedds mannequin commented Aug 21, 2008

    I've been thinking about this a bit, and I don't see how handling it
    should be all that different from handling module renaming.

    For import UserDict, we can just change UserDict to collections and deal
    with UserDict.UserDict with a deprecation warning and
    UserDict.IterableUserDict and UserDict.Mixin with transformations to
    collections.UserDict and collections.MutableMapping.

    For from imports, we can raise the deprecation warning on UserDict, and
    otherwise change from UserDict import ... to from collections import ...
    and then for non-import appearances of UserDict, IterableUserDict, and
    Mixin rename or raise a deprecation warning as appropriate.

    For the other import cases, similar things could be done.

    I think the old version of fix_imports, which had support like this,
    would basically be all that we need. I should be able to mimic that
    functionality, but also make it more scalable than the previous version.

    Is there something I'm missing here about the difference between modules
    and classes? From the use-cases I've observed of UserDict, it seems like
    this functionality would be sufficient.

    @brettcannon
    Copy link
    Member Author

    As I said, it isn't using the import filter, it's whether this should be
    done through a warning instead because the superclasses have changed.

    I really should ask on python-dev about this.

    @brettcannon
    Copy link
    Member Author

    You know what, Nick, go for the fixer. UserDict.UserDict will need a
    deprecation warning, but otherwise a fixer for IterableUserDict and
    DictMixin is fine.

    And I can handle the deprecation if you want.

    @nedds
    Copy link
    Mannequin

    nedds mannequin commented Aug 24, 2008

    How soon is this needed by? I probably won't have a chance to do it in
    the next week, but it shouldn't take that long to make once I get a
    chance to work on it.

    @brettcannon
    Copy link
    Member Author

    On Sun, Aug 24, 2008 at 3:00 PM, Nick Edds <report@bugs.python.org> wrote:

    Nick Edds <nedds@uchicago.edu> added the comment:

    How soon is this needed by? I probably won't have a chance to do it in
    the next week, but it shouldn't take that long to make once I get a
    chance to work on it.

    rc1 is Sep. 3, with rc3 Sep 17 (at the moment). Hitting either should
    be okay, although obviously the sooner the better.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Sep 10, 2008

    I still don't see why this is a release blocker. Adding a 2to3 fixer
    certainly isn't a release blocker - if the fixer isn't available, users
    would need to manually fix the code.

    Adding a Py3k warning shouldn't be a release blocker, either - I think
    such warnings could get added in 2.6.1 also (as they are only issued if
    you invoke Python with -3).

    Tentatively lowering the priority to normal.

    @loewis loewis mannequin removed the release-blocker label Sep 10, 2008
    @nedds
    Copy link
    Mannequin

    nedds mannequin commented Sep 17, 2008

    Sorry about the delay with this. I've finally found some time to work on
    this, so it should be completed within the next couple of days.

    @nedds
    Copy link
    Mannequin

    nedds mannequin commented Sep 27, 2008

    I have the functionality for this working, and will post it tomorrow
    when I complete its test suite.

    @nedds
    Copy link
    Mannequin

    nedds mannequin commented Sep 27, 2008

    Here is a fixer and test suite for the UserDict. It doesn't do a very
    good job handling imports with 'as' right now, but it's core
    functionality appears to be working. If I get a chance I will improve
    its handling of 'as' cases at some point in the future, but I think this
    is an alright start. It passes all tests.

    @nedds
    Copy link
    Mannequin

    nedds mannequin commented Oct 1, 2008

    Could somebody else take a look at this and check in it if it looks
    alright? I think that it works currently but I can't check it in...

    @benjaminp benjaminp self-assigned this Oct 1, 2008
    @benjaminp
    Copy link
    Contributor

    The patch looks very good over all. However, I'm not completely sure
    that 2to3 needs to give a warning on UserDict.UserDict instances.
    Wouldn't it be better to handle that with a py3k warning in UserDict?

    @benjaminp
    Copy link
    Contributor

    Also, I believe the variable initializations at the beginning of the
    transform method are unneeded.

    @ashemedai
    Copy link
    Mannequin

    ashemedai mannequin commented Apr 8, 2010

    What's the consensus on this? I ask since I actually ran into code today that uses DictMixin and as such wasn't converted by the 2to3 tool.

    @rhettinger
    Copy link
    Contributor

    UserDict.DictMixin needs to convert to collections.MutableMapping

    @bitdancer
    Copy link
    Member

    Converting DictMixin to collections.MutableMapping is not necessarily a complete solution. MutableMapping does not provide all the methods that DictMixin does. See for example the problems encountered in bpo-7975.

    @loewis loewis mannequin added topic-2to3 and removed stdlib Python modules in the Lib dir labels Apr 10, 2010
    @brettcannon
    Copy link
    Member Author

    Closing since 2.7 is already out the door.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-2to3 type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants