[Python] Cannot make patch diffs work despite asking different LLMs for hours

Discussão em 'Python' iniciado por Stack, Abril 22, 2025.

  1. Stack

    Stack Membro Participativo

    I am desperately trying to do a simple thing: I have modifications i should do to my code in the forms of "diffs" with the "+" and minuses "-", i give it to you below:

    --- mri_db_gui.py
    +++ mri_db_gui.py
    @@ -1,14 +1,16 @@
    def refresh_image():
    - if display_mode.get() == 'kspace':
    - k = np.fft.fft2(img)
    - k = np.fft.fftshift(k)
    - arr = np.log(np.abs(k) + 1)
    - # Full-range normalization for K-space
    - arr = arr - arr.min()
    - arr = arr / arr.max() * 255
    - else:
    - arr = img
    - # Quantile-based clamp & scale for Image
    - low, high = arr.min(), np.quantile(arr, q_var.get())
    - arr = np.clip(arr, low, high)
    - arr = (arr - low) / (high - low) * 255
    + if display_mode.get() == 'kspace':
    + k = np.fft.fft2(img)
    + k = np.fft.fftshift(k)
    + arr = np.log(np.abs(k) + 1)
    + # Full-range normalization for K-space
    + arr = arr - arr.min()
    + arr = arr / arr.max() * 255
    + else:
    + arr = img
    + # Quantile-based clamp & scale for Image
    + low, high = arr.min(), np.quantile(arr, q_var.get())
    + arr = np.clip(arr, low, high)
    + arr = (arr - low) / (high - low) * 255
    @@ -20,4 +22,6 @@
    -# Hide image widgets initially
    -image_widgets = [image_label, q_label, q_slider] + control_buttons + []
    +# Hide image widgets initially (including Display-mode controls)
    +image_widgets = [
    + image_label, q_label, q_slider,
    + *control_buttons,
    + mode_label, rb_image, rb_kspace
    +]


    This is one version among dozens i ve tried (with and without the "line numbers etc" ). Impossible to apply it. The usual suggestion is to type : patch -p0 < kspace_hide_buttons.patch

    It never works and i get the "garbage" word everytime. Note that of course my mri_db_gui.py is in the same folder as the kspace_hide_buttons.patch ... It is desesperating. I think LLMs are not smart enough, or this diff is too complicated for them to understand. Need human help.

    I simply want to apply those modifications automatically to my mri_db_gui.py file instead of manually changing the code...

    The goal is to apply a patch that has been generated (e.g. by an LLM) in order to automatically modify a file. I never used these "patch" diffs before and dont have time to delve into the details. I thought it would be simple but it does not seem to be, hence i ask the question here. I think this is exactly the purpose of stackoverflow to answer such questions and I do not understand "downvotes".

    Continue reading...

Compartilhe esta Página