July 5, 2022

How f-strings Handle Double Curly Braces

Today I was about setting up a test case for parsing a YAML file which is templated with Jinja variables. Something like this… f""" pipeline: - test jobs: test: package-repositories: - type: apt url: "https://{{auth}}@example.org" """ My test case failed… My Pydantic model, which uses yaml.safe_load under the hood to load the above configuration, returned the URL, even before the value got replaced, as https://{auth}@example.org. One pair of the double curly braces was stripped away!...