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

2to3 fix_renames doesn't rename string.lowercase/uppercase/letters #57481

Closed
ezio-melotti opened this issue Oct 27, 2011 · 5 comments
Closed
Labels
easy topic-2to3 type-bug An unexpected behavior, bug, or error

Comments

@ezio-melotti
Copy link
Member

BPO 13272
Nosy @benjaminp, @ezio-melotti, @meadori, @aldwinaldwin
PRs
  • bpo-13272: 2to3 string constants fixer #14835
  • Superseder
  • bpo-45544: Close 2to3 issues and list them here
  • Files
  • string_partial.patch
  • 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 = None
    closed_at = <Date 2021-10-20.22:58:48.728>
    created_at = <Date 2011-10-27.07:27:05.298>
    labels = ['easy', 'type-bug', 'expert-2to3']
    title = "2to3 fix_renames doesn't rename string.lowercase/uppercase/letters"
    updated_at = <Date 2021-10-20.22:58:48.728>
    user = 'https://github.com/ezio-melotti'

    bugs.python.org fields:

    activity = <Date 2021-10-20.22:58:48.728>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-10-20.22:58:48.728>
    closer = 'iritkatriel'
    components = ['2to3 (2.x to 3.x conversion tool)']
    creation = <Date 2011-10-27.07:27:05.298>
    creator = 'ezio.melotti'
    dependencies = []
    files = ['36586']
    hgrepos = []
    issue_num = 13272
    keywords = ['patch', 'easy']
    message_count = 5.0
    messages = ['146475', '221808', '226659', '226660', '348107']
    nosy_count = 6.0
    nosy_names = ['benjamin.peterson', 'ezio.melotti', 'meador.inge', 'Anthony.Kong', 'superluser', 'aldwinaldwin']
    pr_nums = ['14835']
    priority = 'normal'
    resolution = 'wont fix'
    stage = 'resolved'
    status = 'closed'
    superseder = '45544'
    type = 'behavior'
    url = 'https://bugs.python.org/issue13272'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

    @ezio-melotti
    Copy link
    Member Author

    $ cat deleteme.py 
    from string import lowercase, uppercase, letters
    print uppercase == 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    print lowercase == 'abcdefghijklmnopqrstuvwxyz'
    print letters == 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    $ python deleteme.py 
    True
    True
    True
    $ 2to3 -w deleteme.py 
    RefactoringTool: Skipping implicit fixer: buffer
    RefactoringTool: Skipping implicit fixer: idioms
    RefactoringTool: Skipping implicit fixer: set_literal
    RefactoringTool: Skipping implicit fixer: ws_comma
    RefactoringTool: Refactored deleteme.py
    --- deleteme.py (original)
    +++ deleteme.py (refactored)
    @@ -1,4 +1,4 @@
     from string import lowercase, uppercase, letters
    -print uppercase == 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    -print lowercase == 'abcdefghijklmnopqrstuvwxyz'
    -print letters == 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    +print(uppercase == 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
    +print(lowercase == 'abcdefghijklmnopqrstuvwxyz')
    +print(letters == 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
    RefactoringTool: Files that were modified:
    RefactoringTool: deleteme.py
    $ python3 deleteme.py 
    Traceback (most recent call last):
      File "deleteme.py", line 1, in <module>
        from string import lowercase, uppercase, letters
    ImportError: cannot import name lowercase

    They should be renamed to ascii_*.

    @ezio-melotti ezio-melotti added topic-2to3 type-bug An unexpected behavior, bug, or error labels Oct 27, 2011
    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jun 28, 2014

    @ezio can you prepare a patch for this?

    @superluser
    Copy link
    Mannequin

    superluser mannequin commented Sep 9, 2014

    Changing the imports only is straightforward, but I'm having trouble detecting and changing future uses of the variables, without also clobbering user-defined variables with the same names.

    I notice some of the current fixers have similar problems, for example the itertools fixer changes:

    def imap(): pass
    imap()
    

    to

    def imap(): pass
    map()
    

    This patch is a little smarter than that, but it only detects top-level definitions. For example, the lowercase in

    class Foo:
      def __init__(self):
        self.lowercase = "blargh"
    

    still gets renamed.

    I can work on this more, but would like to know:

    a) whether this fix is still wanted
    b) how smart it needs to be
    c) whether my approach is reasonable. I feel like there should be an easier way.

    @superluser
    Copy link
    Mannequin

    superluser mannequin commented Sep 9, 2014

    ...

    d) how to format code :\

    @aldwinaldwin
    Copy link
    Mannequin

    aldwinaldwin mannequin commented Jul 18, 2019

    • there were many small issues with the patch, improved as good as possible the FixString to catch import as, from string import * and import string

    • did not include the FixStringImports as it's not a necessity to work in Python3

    • indeed, some uses of the constant names that are user-defined will also rename, only when it's in a import string. Added a Caution in the documentation. Still, when all are changed, it should not affect the Python3 version, will just work with the renamed variable name.

    @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
    easy topic-2to3 type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants