Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[blurb] f-string simulation does not work with closures. #299

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

Closed
JulienPalard opened this issue Dec 22, 2018 · 4 comments · Fixed by #386
Closed

[blurb] f-string simulation does not work with closures. #299

JulienPalard opened this issue Dec 22, 2018 · 4 comments · Fixed by #386

Comments

@JulienPalard
Copy link
Member

In the throw function, the raise BlurbError(f("Error in {filename}:{line_number}:\n{s}")) can't find the filename variable leading to:

Traceback (most recent call last):
  File "/home/mdk/clones/core-workflow/blurb/blurb.py", line 1691, in <module>
    main()
  File "/home/mdk/clones/core-workflow/blurb/blurb.py", line 1651, in main
    sys.exit(fn(*filtered_args, **kwargs))
  File "/home/mdk/clones/core-workflow/blurb/blurb.py", line 954, in add
    blurb.load(tmp_path)
  File "/home/mdk/clones/core-workflow/blurb/blurb.py", line 553, in load
    self.parse(text, metadata=metadata, filename=filename)
  File "/home/mdk/clones/core-workflow/blurb/blurb.py", line 543, in parse
    finish_entry()
  File "/home/mdk/clones/core-workflow/blurb/blurb.py", line 495, in finish_entry
    throw("Blurb 'body' text must not be empty!")
  File "/home/mdk/clones/core-workflow/blurb/blurb.py", line 486, in throw
    raise BlurbError(f("Error in {filename}:{line_number}:\n{s}"))
  File "/home/mdk/clones/core-workflow/blurb/blurb.py", line 138, in f
    return s.format_map(d)
KeyError: 'filename'

To reproduce it: invoke blurb, empty the buffer, and close the editor.

I don't think we should try to fix def f, maybe simple add nonlocal filename and nonlocal file_number so they become visible in the function locals.

@Mariatta
Copy link
Member

GitMate.io thinks possibly related issues are #154 (blurb refuse to work without setting EDITOR env), #149 (pip install does not work for cherry_picker), python/devguide#324 (Building docs without make doesn't seem to work), python/blurb#2 (blurb does not support command line options in EDITOR/GIT_EDITOR), and #159 (Make blurb working in Python 3.5.).

@jaraco
Copy link
Member

jaraco commented Oct 29, 2020

I ran into this issue also when implementing a similar function and I ended up creating namespace_format to format a string from the locals and globals. But maybe blurb should just use future-fstrings or just drop support for Python 3.5 (which is EOL anyway).

@JulienPalard
Copy link
Member Author

Dropping Python 3.5 support looks the right way to me too.

@Mariatta
Copy link
Member

I'm in favor of dropping 3.5 support. (#283)

JulienPalard added a commit that referenced this issue May 29, 2021
By dropping the `f()` function (and dropping Python 3.5
compatibility), as the real `f-string` do not have the issue with
non-locals.

closes #299, #300
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants