On 2024-02-19, Chris Green via Python-list <python-list@python.org> wrote:

> It's using f'{...}' at the moment.

Here's a demonstration of how to hook custom code into the f-string
formatting engine. It's brilliantly depraved.

https://stackoverflow.com/questions/55876683/hook-into-the-builtin-python-f-string-format-machinery

>From the above:

    You can, but only if you write evil code that probably should
    never end up in production software. So let's get started!
    
    I'm not going to integrate it into your library, but I will show
    you how to hook into the behavior of f-strings. This is roughly
    how it'll work:
    
     1. Write a function that manipulates the bytecode instructions of
        code objects to replace FORMAT_VALUE instructions with calls
        to a hook function;
    
     2. Customize the import mechanism to make sure that the bytecode
        of every module and package (except standard library modules
        and site-packages) is modified with that function.

Final code is here:

https://github.com/mivdnber/formathack

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to