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

futurize "Stage 2" docs seem outdated #477

Closed
bhrutledge opened this issue Jun 21, 2019 · 5 comments
Closed

futurize "Stage 2" docs seem outdated #477

bhrutledge opened this issue Jun 21, 2019 · 5 comments
Labels

Comments

@bhrutledge
Copy link
Contributor

bhrutledge commented Jun 21, 2019

At http://python-future.org/automatic_conversion.html#stage-2-py3-style-code-with-wrappers-for-py2

Given test_stage2.py:

name = raw_input('What is your name?\n')

for k, v in d.iteritems():
    assert isinstance(v, basestring)

class MyClass(object):
    def __unicode__(self):
        return u'My object'
    def __str__(self):
        return unicode(self).encode('utf-8')

Expected from futurize --stage2 test_stage2.py:

from builtins import input
from builtins import str
from future.utils import iteritems, python_2_unicode_compatible

name = input('What is your name?\n')

for k, v in iteritems(d):
    assert isinstance(v, (str, bytes))

@python_2_unicode_compatible
class MyClass(object):
    def __str__(self):
        return u'My object'

Actual:

from builtins import input
from builtins import str
from past.builtins import basestring
from builtins import object
name = input('What is your name?\n')

for k, v in d.items():
    assert isinstance(v, basestring)

class MyClass(object):
    def __unicode__(self):
        return u'My object'
    def __str__(self):
        return str(self).encode('utf-8')
@bhrutledge bhrutledge changed the title Futurize "Stage 2" docs seem outdated futurize "Stage 2" docs seem outdated Jun 21, 2019
@bhrutledge
Copy link
Contributor Author

Also, the docs say these are the Stage 2 fixers:

lib2to3.fixes.fix_basestring
lib2to3.fixes.fix_dict
lib2to3.fixes.fix_exec
lib2to3.fixes.fix_getcwdu
lib2to3.fixes.fix_input
lib2to3.fixes.fix_itertools
lib2to3.fixes.fix_itertools_imports
lib2to3.fixes.fix_filter
lib2to3.fixes.fix_long
lib2to3.fixes.fix_map
lib2to3.fixes.fix_nonzero
lib2to3.fixes.fix_operator
lib2to3.fixes.fix_raw_input
lib2to3.fixes.fix_zip

libfuturize.fixes.fix_cmp
libfuturize.fixes.fix_division
libfuturize.fixes.fix_execfile
libfuturize.fixes.fix_future_builtins
libfuturize.fixes.fix_future_standard_library
libfuturize.fixes.fix_future_standard_library_urllib
libfuturize.fixes.fix_metaclass
libpasteurize.fixes.fix_newstyle
libfuturize.fixes.fix_object
libfuturize.fixes.fix_unicode_keep_u
libfuturize.fixes.fix_xrange_with_import

However, the current CLI says:

$ futurize --stage2 --list
Available transformations for the -f/--fix option:
lib2to3.fixes.fix_dict
lib2to3.fixes.fix_filter
lib2to3.fixes.fix_getcwdu
lib2to3.fixes.fix_input
lib2to3.fixes.fix_itertools
lib2to3.fixes.fix_itertools_imports
lib2to3.fixes.fix_long
lib2to3.fixes.fix_map
lib2to3.fixes.fix_next
lib2to3.fixes.fix_nonzero
lib2to3.fixes.fix_operator
lib2to3.fixes.fix_raw_input
lib2to3.fixes.fix_zip
libfuturize.fixes.fix_basestring
libfuturize.fixes.fix_cmp
libfuturize.fixes.fix_division_safe
libfuturize.fixes.fix_execfile
libfuturize.fixes.fix_future_builtins
libfuturize.fixes.fix_future_standard_library
libfuturize.fixes.fix_future_standard_library_urllib
libfuturize.fixes.fix_metaclass
libfuturize.fixes.fix_object
libfuturize.fixes.fix_unicode_keep_u
libfuturize.fixes.fix_xrange_with_import
libpasteurize.fixes.fix_newstyle

Here's a diff of the docs to the CLI:

1d0
< lib2to3.fixes.fix_basestring
3d1
< lib2to3.fixes.fix_exec
10a9
> lib2to3.fixes.fix_next
14a14
> libfuturize.fixes.fix_basestring
16c16
< libfuturize.fixes.fix_division
---
> libfuturize.fixes.fix_division_safe

@youtux
Copy link

youtux commented Aug 7, 2019

I am encountering the same problem. The converted code has different semantics, i.e. it allocates a list now instead of iterating over the values (in py2).

This is going to make it quite difficult to use this tool for me.

@ilya-palachev
Copy link

ilya-palachev commented Feb 20, 2020

By the way, I have installation (Ubuntu 18.04 and pip3 install future, now it's version is 0.15.2) in which lib2to3.fixes.fix_next and libfuturize.fixes.fix_next_call present simultaneously:

$ python3-futurize -l | grep next
lib2to3.fixes.fix_next
libfuturize.fixes.fix_next_call

I have some code for which lib2to3.fixes.fix_next gives 52 suggestions and libfuturize.fixes.fix_next_call gives 14 suggestions in one run!
How is this possible?
Seems that there is some bug here.

@sfdye
Copy link
Collaborator

sfdye commented Jun 10, 2020

Thanks for reporting, will update the docs soon

@sfdye sfdye pinned this issue Jun 13, 2020
@sfdye sfdye added the docs label Jun 13, 2020
@sfdye sfdye unpinned this issue Jun 13, 2020
@sfdye
Copy link
Collaborator

sfdye commented Jun 13, 2020

I believe this is fixed in latest docs, just not published. Close in favor of #511 so we have one single place to track.

@sfdye sfdye closed this as completed Jun 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants