Skip to content

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

Description

@JulienPalard

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions