Skip to content

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

Closed

Description

@ezio-melotti
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']

    Activity

    1. ezio-melotti commented on Oct 27, 2011

      @ezio-melotti
      MemberAuthor
      $ 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_*.

    2. BreamoreBoy commented on Jun 28, 2014

      BreamoreBoymannequin
      Mannequin

      @ezio can you prepare a patch for this?

    3. superluser commented on Sep 9, 2014

      superlusermannequin
      Mannequin

      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.

    4. superluser commented on Sep 9, 2014

      superlusermannequin
      Mannequin

      ...

      d) how to format code :\

    5. aldwinaldwin commented on Jul 18, 2019

      aldwinaldwinmannequin
      Mannequin
      • 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.

    6. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions