Skip to content

2to3 wrong for types.StringTypes #49675

Closed

Description

@hagen
mannequin
BPO 5425
Nosy @loewis, @devdanzin, @benjaminp
Files
  • 2to3_StringTypes.patch
  • 2to3_StringTypes_2.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 2009-03-18.21:13:30.601>
    created_at = <Date 2009-03-05.14:48:48.098>
    labels = ['type-bug', 'expert-2to3']
    title = '2to3 wrong for types.StringTypes'
    updated_at = <Date 2009-03-18.21:13:30.599>
    user = 'https://bugs.python.org/hagen'

    bugs.python.org fields:

    activity = <Date 2009-03-18.21:13:30.599>
    actor = 'benjamin.peterson'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-03-18.21:13:30.601>
    closer = 'benjamin.peterson'
    components = ['2to3 (2.x to 3.x conversion tool)']
    creation = <Date 2009-03-05.14:48:48.098>
    creator = 'hagen'
    dependencies = []
    files = ['13248', '13265']
    hgrepos = []
    issue_num = 5425
    keywords = ['patch']
    message_count = 9.0
    messages = ['83198', '83215', '83221', '83240', '83252', '83276', '83289', '83311', '83777']
    nosy_count = 4.0
    nosy_names = ['loewis', 'ajaksu2', 'benjamin.peterson', 'hagen']
    pr_nums = []
    priority = 'normal'
    resolution = 'rejected'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue5425'
    versions = ['Python 2.6', 'Python 3.0']

    Activity

    1. hagen commented on Mar 5, 2009

      hagenmannequin
      MannequinAuthor

      In Python 2.6 we have

      >>> types.StringTypes
      (<type 'str'>, <type 'unicode'>)

      but 2to3 translates "types.StringTypes" into "str", which is obviously
      wrong. The attached patch changes it into "(str, bytes)".

    2. added
      type-bug
      on Mar 5, 2009
    3. benjaminp commented on Mar 5, 2009

      @benjaminp
      Contributor

      It's hard to guess the intention of types.StringTypes since it may mean
      "text" strings or "text and byte" strings. I'm tempted to just remove
      the transformation at all and issue a warning.

    4. loewis commented on Mar 5, 2009

      loewismannequin
      Mannequin

      I agree with Benjamin. Translation into (str, bytes) is incorrect. I
      don't agree that it is obvious that the translation into str is incorrect.

      Recommend closing as reject.

    5. hagen commented on Mar 6, 2009

      hagenmannequin
      MannequinAuthor

      Why I considered the existing translation incorrect was because it
      translates something which was a tuple of types in Python 2.x into a
      type of Python 3.x. I fail to see how this can be useful. (A check like
      "x in types.StringTypes" gets translated into "x in str", which will
      always fail.)

      I agree that translating into "(str, bytes)" won't always be correct,
      but it seems to have a much better chance of being correct than the
      existing translation into "str". Otherwise it should at least be "(str,)".

    6. loewis commented on Mar 6, 2009

      loewismannequin
      Mannequin

      Why I considered the existing translation incorrect was because it
      translates something which was a tuple of types in Python 2.x into a
      type of Python 3.x. I fail to see how this can be useful.

      It would translate "isinstance(x, types.StringTypes)" correctly. I agree
      that translating to a tuple would be correct in more cases.

    7. hagen commented on Mar 7, 2009

      hagenmannequin
      MannequinAuthor

      I can see the merit of not including "bytes" in StringTypes, but then
      the translation of StringType should be changed accordingly. How about
      changing the present

      StringType -> bytes
      StringTypes -> str

      into

      StringType -> str
      StringTypes -> (str,)

    8. devdanzin commented on Mar 7, 2009

      devdanzinmannequin
      Mannequin

      I think Hagen's initial analysis makes more sense: the translation is
      currently guessing that the user meant the more restrict (text) alternative.

      IMHO it doesn't make much sense to have this:
      >>> strings = (types.StringType, types.UnicodeType)
      >>> strings == types.StringTypes
      True

      Translated to this:
      strings = (bytes, str)
      strings == str

    9. hagen commented on Mar 8, 2009

      hagenmannequin
      MannequinAuthor

      The automatic conversion can't be perfect in all cases, but I think my
      second suggestion is more in line with the other transformations done by
      2to3 (string literals, "str", "basestring" etc.).

      I propose applying the second patch, but don't care enough to argue for
      it much more if it's rejected.

    10. reopened this on Mar 8, 2009
    11. benjaminp commented on Mar 18, 2009

      @benjaminp
      Contributor

      I'm rejecting this patch again not because I think it's any worse than
      the status quo (I think they're about equally incorrect/correct), but
      because this is now released behavior and changing it may result in
      backwards incompatibility. Also, people can easily remove this ambiguity
      in a 2.x compatible fashion by explicitly listing the types (str,) or
      (str, unicode) instead of using the types module.

    12. 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

      topic-2to3type-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions