Code Monkey home page Code Monkey logo

f2format's People

Contributors

actions-user avatar gousaiyang avatar jarryshaw avatar pyup-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

f2format's Issues

parser: SyntaxError: cannot delete starred

del with multiple values of trailing comma is not parsed correctly

echo 'a=1;del a,' | f2format -s
Traceback (most recent call last):
  File "/Users/user/bin/f2format", line 8, in <module>
    sys.exit(main())
  File "<string>", line None
bpc_utils.parsing.BPCSyntaxError: source file '<unknown>' contains the following syntax errors:
[L1C4] SyntaxError: cannot delete starred

Code with invalid quotes get successfully converted

Describe the bug
Code with invalid quotes get successfully converted.

To Reproduce

>>> import f2format
>>> s = 'hello'
>>> code = "f'{s + ''}'"
>>> print(f2format.convert(code))
'{}'.format(s + '')
>>> eval(code)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1
SyntaxError: f-string: expecting '}'
>>>

Expected behavior
f2format.convert() should raise an error to report that the code is invalid

yield in lambdas mishandled

echo 'type((lambda: (yield))())' | ~/.local/bin/f2format -s 
Traceback (most recent call last):
  File "/Users/user/.local/bin/f2format", line 8, in <module>
    sys.exit(main())
  File "<string>", line None
bpc_utils.parsing.BPCSyntaxError: source file '<unknown>' contains the following syntax errors:
[L1C14] SyntaxError: 'yield' outside function

"SyntaxError: invalid syntax" error on a line with a ternary conditional operator

I have a Python source file (see attachment) that gives the following error when I try to convert it with f2format v0.4.3 on Ubuntu 18.04 64-bit using Python 3.6.5:
Traceback (most recent call last): File "/opt/design/python/lib/python3.6/multiprocessing/pool.py", line 119, in worker result = (True, func(*args, **kwds)) File "/opt/design/python/lib/python3.6/multiprocessing/pool.py", line 44, in mapstar return list(map(*args)) File "/opt/design/python/lib/python3.6/site-packages/f2format/core.py", line 244, in f2format text = convert(string, lineno) File "/opt/design/python/lib/python3.6/site-packages/f2format/core.py", line 185, in convert val = ast.parse(temp_expr).body[0].value # parse AST File "/opt/design/python/lib/python3.6/ast.py", line 35, in parse return compile(source, filename, mode, PyCF_ONLY_AST) File "<unknown>", line 1 address:0{self.axi_address_width // 4 + (1 if self.axi_address_width % 4 != 0 else 0) ^ SyntaxError: invalid syntax

I suspect it because of the ternary conditional operator in that line of code.
xilinx.py.zip

Some nested f-strings with double quotes are not converted

It seems that some nested f-strings with double quotes are not converted. For example:

# Code:
logger.debug(f'[{", ".join([f"0x{item:04X}" for item in data])}]')

# Gets converted to:
logger.debug('[{}]'.format(", ".join([f"0x{item:04X}" for item in data])))

# Code:
logger.error(f'FAIL: Wrong response to an invalid command 0x{command:02X} from FTDI device, port {port}: [{", ".join([f"0x{item:02X}" for item in data_r])}]')

# Gets converted to:
logger.error('FAIL: Wrong response to an invalid command 0x{:02X} from FTDI device, port {}: [{}]'.format(command, port, ", ".join([f"0x{item:02X}" for item in data_r])))

See code in the attachment

I'm running the latest f2format from Git under Python 3.6.5.
ftdi.py.zip

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.