Comments (8)
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:
Lines 150 to 151 in 68fbf65
from astor.
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.
Thanks! I'll check what's wrong with 3.6.3 this weekend.
from astor.
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.
@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.
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.
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.
@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)
- ast.to_source does not return a valid source code (Call with f-string argument) HOT 1
- Deleted
- 0.8.1: test suite i sfailing HOT 1
- Cannot roundtrip Python 3.9 stdlib xml/dom/minidom.py
- Uneeded triplequotes added in round trip
- 0.8.1 keeps failing with NotADirectoryError HOT 3
- Missing parentheses in dictionary unpacking HOT 1
- to_source raises AssertionError
- AttributeError: 'FunctionDef' object has no attribute 'decorator_list'
- Can't find implementation of method `SourceGenerator.get__pp` HOT 2
- Retire `astor`, as `ast.unparse` exists, and migrate it into API-compatible shims of `ast` for older versions of python HOT 3
- Example to insert python code through AST
- Python 3.10.7 is now more careful with huge integers HOT 2
- SyntaxError: invalid syntax HOT 2
- AttributeError: No defined handler for node of type Match HOT 2
- Pypi release? HOT 2
- [3.12] DeprecationWarning: ast.Num is deprecated and will be removed in Python 3.14; use ast.Constant instead
- Switch to use GitHub Actions
- why the type of variable βNEW_PARAM_JIN is wrong
- astor.to_source pretty_string HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from astor.