Code Monkey home page Code Monkey logo

Comments (8)

berkerpeksag avatar berkerpeksag commented on July 18, 2024

Thanks for the report. I think the cause of both failures is f-strings. We probably miss some cases when we implement it. Also, did you get any output from astor.rtrip? It should normally prints out broken nodes:

astor/astor/rtrip.py

Lines 150 to 151 in 68fbf65

if bad_nodes:
logging.error('\nERROR -- UNKNOWN NODES STRIPPED: %s' % bad_nodes)

from astor.

felixonmars avatar felixonmars commented on July 18, 2024

Hrm, didn't see that.

root: INFO: Converting /usr/lib/python3.6/idlelib/grep.py
root: WARNING:     calculating dump -- bad
root: INFO: Converting /usr/lib/python3.6/test/test_fstring.py
root: WARNING:     calculating dump -- bad
Files failed to round-trip to AST:
root: WARNING:     /usr/lib/python3.6/test/test_fstring.py
root: WARNING:     /usr/lib/python3.6/idlelib/grep.py

That's all I found besides other INFO entries.

from astor.

berkerpeksag avatar berkerpeksag commented on July 18, 2024

Thanks! I'll check what's wrong with 3.6.3 this weekend.

from astor.

radomirbosak avatar radomirbosak commented on July 18, 2024

How do I reproduce this? For me all tests pass

$ python3.6 -m nose -v
test_annassign (tests.test_code_gen.CodegenTestCase) ... ok
[...]
test_codegen_from_root (tests.test_misc.PublicAPITestCase) ... ok
test_convert_stdlib (tests.test_rtrip.RtripTestCase) ... ok

----------------------------------------------------------------------
Ran 34 tests in 18.100s

OK

The same happens when running via tox:

$ tox -e py36
py36 develop-inst-noop: /home/lukoa/repos/astor
py36 installed: -e [email protected]:radomirbosak/astor.git@b47718fa095e456c064d3d222f296fccfe36266b#egg=astor,nose==1.3.7
py36 runtests: PYTHONHASHSEED='2587239569'
py36 runtests: commands[0] | nosetests -v --nocapture
test_annassign (tests.test_code_gen.CodegenTestCase) ... ok
[...]
test_codegen_from_root (tests.test_misc.PublicAPITestCase) ... ok
test_convert_stdlib (tests.test_rtrip.RtripTestCase) ... ok

----------------------------------------------------------------------
Ran 34 tests in 16.442s

OK
__________________________________ summary ___________________________________
  py36: commands succeeded
  congratulations :)

from astor.

berkerpeksag avatar berkerpeksag commented on July 18, 2024

@radomirbosak, thank you for trying to reproduce this! Do you have the latest 3.6 release? (If you have 3.6.5 installed with stdlib tests and IDLE installed, I think we can close this as outdated)

Note that almost all distros don't include stdlib tests and don't install IDLE by default. So you may want to check whether test/test_fstring.py and idlelib/grep.py tested by test_convert_stdlib.

from astor.

felixonmars avatar felixonmars commented on July 18, 2024

I'm still getting this in 3.6.5 - besides one more missing item:

======================================================================
FAIL: test_convert_stdlib (tests.test_rtrip.RtripTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/python-astor/src/astor-0.6.2/tests/test_rtrip.py", line 24, in test_convert_stdlib
    self.assertEqual(result, [])
AssertionError: Lists differ: ['/usr/lib/python3.6/netrc.py', '/usr/lib/[65 chars].py'] != []

First list contains 3 additional elements.
First extra element 0:
'/usr/lib/python3.6/netrc.py'

+ []
- ['/usr/lib/python3.6/netrc.py',
-  '/usr/lib/python3.6/test/test_fstring.py',
-  '/usr/lib/python3.6/idlelib/grep.py']
Files failed to round-trip to AST:
root: WARNING:     /usr/lib/python3.6/netrc.py
root: WARNING:     /usr/lib/python3.6/test/test_fstring.py
root: WARNING:     /usr/lib/python3.6/idlelib/grep.py

from astor.

berkerpeksag avatar berkerpeksag commented on July 18, 2024

The only change that we made to Lib/netrc.py in the 3.6 branch is python/cpython@5fbe5e1.

I think there is an escaping issue here. Here's a simple test case:

def test_issue_89(self):
    source = """
    x = f'{host}\\n\\t{port}\\n'
    """
    self.assertSrcRoundtripsGtVer(source, (3, 6))

Test result:

======================================================================
FAIL: test_issue_89 (tests.test_code_gen.CodegenTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/berker/projects/astor/tests/test_code_gen.py", line 414, in test_issue_89
    self.assertSrcRoundtripsGtVer(source, (3, 6))
  File "/home/berker/projects/astor/tests/test_code_gen.py", line 74, in assertSrcRoundtripsGtVer
    self.assertSrcRoundtrips(source)
  File "/home/berker/projects/astor/tests/test_code_gen.py", line 62, in assertSrcRoundtrips
    self.assertEqual(self.to_source(ast.parse(srctxt)).rstrip(), srctxt)
AssertionError: "x = \nf'{host}\\n\\t{port}'" != "x = f'{host}\\n\\t{port}\\n'"

Also, if I drop the trailing \n, the test will pass:

source = """
x = f'{host}\\n\\t{port}'
"""

@radomirbosak would you like to work on this?

from astor.

radomirbosak avatar radomirbosak commented on July 18, 2024

@berkerpeksag I can take a look.

After installing the stdlib tests and idle packages I was able to reproduce the issue (on python 3.6.5).

from astor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.