prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Don't display redundant form field labels
  - Don't display redundant field labels 
  - Retain field labels for screenreaders
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `src/registrar/templatetags/field_helpers.py`
  Content:
  ```
  1 """Custom field helpers for our inputs."""
  2 import re
  3 
  4 from django import template
  5 
  6 register = template.Library()
  7 
  8 
  9 @register.inclusion_tag("includes/input_with_errors.html", takes_context=True)
  10 def input_with_errors(context, field=None):  # noqa: C901
  11     """Make an input field along with error handling.
  12 
  13     Args:
  14         field: The field instance.
  15 
  16     In addition to the explicit `field` argument, this inclusion_tag takes the
  17     following "widget-tweak-esque" parameters from the surrounding context.
  18 
  19     Context args:
  20         add_class: append to input element's `class` attribute
  21         add_error_class: like `add_class` but only if field.errors is not empty
  22         add_required_class: like `add_class` but only if field is required
  23         add_label_class: append to input element's label's `class` attribute
  24         add_group_class: append to input element's surrounding tag's `class` attribute
  25         attr_* - adds or replaces any single html attribute for the input
  26         add_error_attr_* - like `attr_*` but only if field.errors is not empty
  27 
  28     Example usage:
  29         ```
  30         {% for form in forms.0 %}
  31             {% with add_class="usa-input--medium" %}
  32                 {% with attr_required=True attr_disabled=False %}
  33                     {% input_with_errors form.street_address1 %}
  34                 {% endwith %}
  35             {% endwith %}
  36         {% endfor }
  37 
  38     There are a few edge cases to keep in mind:
  39         - a "maxlength" attribute will cause the input to use USWDS Character counter
  40         - the field's `use_fieldset` controls whether the output is label/field or
  41             fieldset/legend/field
  42         - checkbox label styling is different (this is handled, don't worry about it)
  43     """
  44     context = context.flatten()
  45     context["field"] = field
  46 
  47     # get any attributes specified in the field's definition
  48     attrs = dict(field.field.widget.attrs)
  49 
  50     # these will be converted to CSS strings
  51     classes = []
  52     label_classes = []
  53     group_classes = []
  54 
  55     # this will be converted to an attribute string
  56     described_by = []
  57 
  58     if "class" in attrs:
  59         classes.append(attrs.pop("class"))
  60 
  61     # parse context for field attributes and classes
  62     # ---
  63     # here we loop through all items in the context dictionary
  64     # (this is the context which was being used to render the
  65     #  outer template in which this {% input_with_errors %} appeared!)
  66     # and look for "magic" keys -- these are used to modify the
  67     # appearance and behavior of the final HTML
  68     for key, value in context.items():
  69         if key.startswith("attr_"):
  70             attr_name = re.sub("_", "-", key[5:])
  71             attrs[attr_name] = value
  72         elif key.startswith("add_error_attr_") and field.errors:
  73             attr_name = re.sub("_", "-", key[15:])
  74             attrs[attr_name] = value
  75 
  76         elif key == "add_class":
  77             classes.append(value)
  78         elif key == "add_required_class" and field.required:
  79             classes.append(value)
  80         elif key == "add_error_class" and field.errors:
  81             classes.append(value)
  82 
  83         elif key == "add_label_class":
  84             label_classes.append(value)
  85 
  86         elif key == "add_group_class":
  87             group_classes.append(value)
  88 
  89     attrs["id"] = field.auto_id
  90 
  91     # do some work for various edge cases
  92 
  93     if "maxlength" in attrs:
  94         # associate the field programmatically with its hint text
  95         described_by.append(f"{attrs['id']}__message")
  96 
  97     if field.use_fieldset:
  98         context["label_tag"] = "legend"
  99     else:
  100         context["label_tag"] = "label"
  101 
  102     if field.use_fieldset:
  103         label_classes.append("usa-legend")
  104 
  105     if field.widget_type == "checkbox":
  106         label_classes.append("usa-checkbox__label")
  107     elif not field.use_fieldset:
  108         label_classes.append("usa-label")
  109 
  110     if field.errors:
  111         # associate the field programmatically with its error message
  112         message_div_id = f"{attrs['id']}__error-message"
  113         described_by.append(message_div_id)
  114 
  115         # set the field invalid
  116         # due to weirdness, this must be a string, not a boolean
  117         attrs["aria-invalid"] = "true"
  118 
  119         # style the invalid field
  120         classes.append("usa-input--error")
  121         label_classes.append("usa-label--error")
  122         group_classes.append("usa-form-group--error")
  123 
  124     # convert lists into strings
  125 
  126     if classes:
  127         context["classes"] = " ".join(classes)
  128 
  129     if label_classes:
  130         context["label_classes"] = " ".join(label_classes)
  131 
  132     if group_classes:
  133         context["group_classes"] = " ".join(group_classes)
  134 
  135     if described_by:
  136         # ensure we don't overwrite existing attribute value
  137         if "aria-describedby" in attrs:
  138             described_by.append(attrs["aria-describedby"])
  139         attrs["aria-describedby"] = " ".join(described_by)
  140 
  141     # ask Django to give us the widget dict
  142     # see Widget.get_context() on
  143     # https://docs.djangoproject.com/en/4.1/ref/forms/widgets
  144     widget = field.field.widget.get_context(
  145         field.html_name, field.value() or field.initial, field.build_widget_attrs(attrs)
  146     )  # -> {"widget": {"name": ...}}
  147 
  148     context["widget"] = widget["widget"]
  149 
  150     return context
  151
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/src/registrar/templatetags/field_helpers.py b/src/registrar/templatetags/field_helpers.py
  --- a/src/registrar/templatetags/field_helpers.py
  +++ b/src/registrar/templatetags/field_helpers.py
  @@ -21,6 +21,7 @@
           add_error_class: like `add_class` but only if field.errors is not empty
           add_required_class: like `add_class` but only if field is required
           add_label_class: append to input element's label's `class` attribute
  +        add_legend_class: append to input element's legend's `class` attribute
           add_group_class: append to input element's surrounding tag's `class` attribute
           attr_* - adds or replaces any single html attribute for the input
           add_error_attr_* - like `attr_*` but only if field.errors is not empty
  @@ -50,6 +51,7 @@
       # these will be converted to CSS strings
       classes = []
       label_classes = []
  +    legend_classes = []
       group_classes = []
   
       # this will be converted to an attribute string
  @@ -82,6 +84,8 @@
   
           elif key == "add_label_class":
               label_classes.append(value)
  +        elif key == "add_legend_class":
  +            legend_classes.append(value)
   
           elif key == "add_group_class":
               group_classes.append(value)
  @@ -129,6 +133,9 @@
       if label_classes:
           context["label_classes"] = " ".join(label_classes)
   
  +    if legend_classes:
  +        context["legend_classes"] = " ".join(legend_classes)
  +
       if group_classes:
           context["group_classes"] = " ".join(group_classes)
  
verification_info: {"golden_diff": "diff --git a/src/registrar/templatetags/field_helpers.py b/src/registrar/templatetags/field_helpers.py\n--- a/src/registrar/templatetags/field_helpers.py\n+++ b/src/registrar/templatetags/field_helpers.py\n@@ -21,6 +21,7 @@\n         add_error_class: like `add_class` but only if field.errors is not empty\n         add_required_class: like `add_class` but only if field is required\n         add_label_class: append to input element's label's `class` attribute\n+        add_legend_class: append to input element's legend's `class` attribute\n         add_group_class: append to input element's surrounding tag's `class` attribute\n         attr_* - adds or replaces any single html attribute for the input\n         add_error_attr_* - like `attr_*` but only if field.errors is not empty\n@@ -50,6 +51,7 @@\n     # these will be converted to CSS strings\n     classes = []\n     label_classes = []\n+    legend_classes = []\n     group_classes = []\n \n     # this will be converted to an attribute string\n@@ -82,6 +84,8 @@\n \n         elif key == \"add_label_class\":\n             label_classes.append(value)\n+        elif key == \"add_legend_class\":\n+            legend_classes.append(value)\n \n         elif key == \"add_group_class\":\n             group_classes.append(value)\n@@ -129,6 +133,9 @@\n     if label_classes:\n         context[\"label_classes\"] = \" \".join(label_classes)\n \n+    if legend_classes:\n+        context[\"legend_classes\"] = \" \".join(legend_classes)\n+\n     if group_classes:\n         context[\"group_classes\"] = \" \".join(group_classes)\n", "issue": "Don't display redundant form field labels\n- Don't display redundant field labels \n- Retain field labels for screenreaders\n", "before_files": [{"content": "\"\"\"Custom field helpers for our inputs.\"\"\"\nimport re\n\nfrom django import template\n\nregister = template.Library()\n\n\n@register.inclusion_tag(\"includes/input_with_errors.html\", takes_context=True)\ndef input_with_errors(context, field=None):  # noqa: C901\n    \"\"\"Make an input field along with error handling.\n\n    Args:\n        field: The field instance.\n\n    In addition to the explicit `field` argument, this inclusion_tag takes the\n    following \"widget-tweak-esque\" parameters from the surrounding context.\n\n    Context args:\n        add_class: append to input element's `class` attribute\n        add_error_class: like `add_class` but only if field.errors is not empty\n        add_required_class: like `add_class` but only if field is required\n        add_label_class: append to input element's label's `class` attribute\n        add_group_class: append to input element's surrounding tag's `class` attribute\n        attr_* - adds or replaces any single html attribute for the input\n        add_error_attr_* - like `attr_*` but only if field.errors is not empty\n\n    Example usage:\n        ```\n        {% for form in forms.0 %}\n            {% with add_class=\"usa-input--medium\" %}\n                {% with attr_required=True attr_disabled=False %}\n                    {% input_with_errors form.street_address1 %}\n                {% endwith %}\n            {% endwith %}\n        {% endfor }\n\n    There are a few edge cases to keep in mind:\n        - a \"maxlength\" attribute will cause the input to use USWDS Character counter\n        - the field's `use_fieldset` controls whether the output is label/field or\n            fieldset/legend/field\n        - checkbox label styling is different (this is handled, don't worry about it)\n    \"\"\"\n    context = context.flatten()\n    context[\"field\"] = field\n\n    # get any attributes specified in the field's definition\n    attrs = dict(field.field.widget.attrs)\n\n    # these will be converted to CSS strings\n    classes = []\n    label_classes = []\n    group_classes = []\n\n    # this will be converted to an attribute string\n    described_by = []\n\n    if \"class\" in attrs:\n        classes.append(attrs.pop(\"class\"))\n\n    # parse context for field attributes and classes\n    # ---\n    # here we loop through all items in the context dictionary\n    # (this is the context which was being used to render the\n    #  outer template in which this {% input_with_errors %} appeared!)\n    # and look for \"magic\" keys -- these are used to modify the\n    # appearance and behavior of the final HTML\n    for key, value in context.items():\n        if key.startswith(\"attr_\"):\n            attr_name = re.sub(\"_\", \"-\", key[5:])\n            attrs[attr_name] = value\n        elif key.startswith(\"add_error_attr_\") and field.errors:\n            attr_name = re.sub(\"_\", \"-\", key[15:])\n            attrs[attr_name] = value\n\n        elif key == \"add_class\":\n            classes.append(value)\n        elif key == \"add_required_class\" and field.required:\n            classes.append(value)\n        elif key == \"add_error_class\" and field.errors:\n            classes.append(value)\n\n        elif key == \"add_label_class\":\n            label_classes.append(value)\n\n        elif key == \"add_group_class\":\n            group_classes.append(value)\n\n    attrs[\"id\"] = field.auto_id\n\n    # do some work for various edge cases\n\n    if \"maxlength\" in attrs:\n        # associate the field programmatically with its hint text\n        described_by.append(f\"{attrs['id']}__message\")\n\n    if field.use_fieldset:\n        context[\"label_tag\"] = \"legend\"\n    else:\n        context[\"label_tag\"] = \"label\"\n\n    if field.use_fieldset:\n        label_classes.append(\"usa-legend\")\n\n    if field.widget_type == \"checkbox\":\n        label_classes.append(\"usa-checkbox__label\")\n    elif not field.use_fieldset:\n        label_classes.append(\"usa-label\")\n\n    if field.errors:\n        # associate the field programmatically with its error message\n        message_div_id = f\"{attrs['id']}__error-message\"\n        described_by.append(message_div_id)\n\n        # set the field invalid\n        # due to weirdness, this must be a string, not a boolean\n        attrs[\"aria-invalid\"] = \"true\"\n\n        # style the invalid field\n        classes.append(\"usa-input--error\")\n        label_classes.append(\"usa-label--error\")\n        group_classes.append(\"usa-form-group--error\")\n\n    # convert lists into strings\n\n    if classes:\n        context[\"classes\"] = \" \".join(classes)\n\n    if label_classes:\n        context[\"label_classes\"] = \" \".join(label_classes)\n\n    if group_classes:\n        context[\"group_classes\"] = \" \".join(group_classes)\n\n    if described_by:\n        # ensure we don't overwrite existing attribute value\n        if \"aria-describedby\" in attrs:\n            described_by.append(attrs[\"aria-describedby\"])\n        attrs[\"aria-describedby\"] = \" \".join(described_by)\n\n    # ask Django to give us the widget dict\n    # see Widget.get_context() on\n    # https://docs.djangoproject.com/en/4.1/ref/forms/widgets\n    widget = field.field.widget.get_context(\n        field.html_name, field.value() or field.initial, field.build_widget_attrs(attrs)\n    )  # -> {\"widget\": {\"name\": ...}}\n\n    context[\"widget\"] = widget[\"widget\"]\n\n    return context\n", "path": "src/registrar/templatetags/field_helpers.py"}], "after_files": [{"content": "\"\"\"Custom field helpers for our inputs.\"\"\"\nimport re\n\nfrom django import template\n\nregister = template.Library()\n\n\n@register.inclusion_tag(\"includes/input_with_errors.html\", takes_context=True)\ndef input_with_errors(context, field=None):  # noqa: C901\n    \"\"\"Make an input field along with error handling.\n\n    Args:\n        field: The field instance.\n\n    In addition to the explicit `field` argument, this inclusion_tag takes the\n    following \"widget-tweak-esque\" parameters from the surrounding context.\n\n    Context args:\n        add_class: append to input element's `class` attribute\n        add_error_class: like `add_class` but only if field.errors is not empty\n        add_required_class: like `add_class` but only if field is required\n        add_label_class: append to input element's label's `class` attribute\n        add_legend_class: append to input element's legend's `class` attribute\n        add_group_class: append to input element's surrounding tag's `class` attribute\n        attr_* - adds or replaces any single html attribute for the input\n        add_error_attr_* - like `attr_*` but only if field.errors is not empty\n\n    Example usage:\n        ```\n        {% for form in forms.0 %}\n            {% with add_class=\"usa-input--medium\" %}\n                {% with attr_required=True attr_disabled=False %}\n                    {% input_with_errors form.street_address1 %}\n                {% endwith %}\n            {% endwith %}\n        {% endfor }\n\n    There are a few edge cases to keep in mind:\n        - a \"maxlength\" attribute will cause the input to use USWDS Character counter\n        - the field's `use_fieldset` controls whether the output is label/field or\n            fieldset/legend/field\n        - checkbox label styling is different (this is handled, don't worry about it)\n    \"\"\"\n    context = context.flatten()\n    context[\"field\"] = field\n\n    # get any attributes specified in the field's definition\n    attrs = dict(field.field.widget.attrs)\n\n    # these will be converted to CSS strings\n    classes = []\n    label_classes = []\n    legend_classes = []\n    group_classes = []\n\n    # this will be converted to an attribute string\n    described_by = []\n\n    if \"class\" in attrs:\n        classes.append(attrs.pop(\"class\"))\n\n    # parse context for field attributes and classes\n    # ---\n    # here we loop through all items in the context dictionary\n    # (this is the context which was being used to render the\n    #  outer template in which this {% input_with_errors %} appeared!)\n    # and look for \"magic\" keys -- these are used to modify the\n    # appearance and behavior of the final HTML\n    for key, value in context.items():\n        if key.startswith(\"attr_\"):\n            attr_name = re.sub(\"_\", \"-\", key[5:])\n            attrs[attr_name] = value\n        elif key.startswith(\"add_error_attr_\") and field.errors:\n            attr_name = re.sub(\"_\", \"-\", key[15:])\n            attrs[attr_name] = value\n\n        elif key == \"add_class\":\n            classes.append(value)\n        elif key == \"add_required_class\" and field.required:\n            classes.append(value)\n        elif key == \"add_error_class\" and field.errors:\n            classes.append(value)\n\n        elif key == \"add_label_class\":\n            label_classes.append(value)\n        elif key == \"add_legend_class\":\n            legend_classes.append(value)\n\n        elif key == \"add_group_class\":\n            group_classes.append(value)\n\n    attrs[\"id\"] = field.auto_id\n\n    # do some work for various edge cases\n\n    if \"maxlength\" in attrs:\n        # associate the field programmatically with its hint text\n        described_by.append(f\"{attrs['id']}__message\")\n\n    if field.use_fieldset:\n        context[\"label_tag\"] = \"legend\"\n    else:\n        context[\"label_tag\"] = \"label\"\n\n    if field.use_fieldset:\n        label_classes.append(\"usa-legend\")\n\n    if field.widget_type == \"checkbox\":\n        label_classes.append(\"usa-checkbox__label\")\n    elif not field.use_fieldset:\n        label_classes.append(\"usa-label\")\n\n    if field.errors:\n        # associate the field programmatically with its error message\n        message_div_id = f\"{attrs['id']}__error-message\"\n        described_by.append(message_div_id)\n\n        # set the field invalid\n        # due to weirdness, this must be a string, not a boolean\n        attrs[\"aria-invalid\"] = \"true\"\n\n        # style the invalid field\n        classes.append(\"usa-input--error\")\n        label_classes.append(\"usa-label--error\")\n        group_classes.append(\"usa-form-group--error\")\n\n    # convert lists into strings\n\n    if classes:\n        context[\"classes\"] = \" \".join(classes)\n\n    if label_classes:\n        context[\"label_classes\"] = \" \".join(label_classes)\n\n    if legend_classes:\n        context[\"legend_classes\"] = \" \".join(legend_classes)\n\n    if group_classes:\n        context[\"group_classes\"] = \" \".join(group_classes)\n\n    if described_by:\n        # ensure we don't overwrite existing attribute value\n        if \"aria-describedby\" in attrs:\n            described_by.append(attrs[\"aria-describedby\"])\n        attrs[\"aria-describedby\"] = \" \".join(described_by)\n\n    # ask Django to give us the widget dict\n    # see Widget.get_context() on\n    # https://docs.djangoproject.com/en/4.1/ref/forms/widgets\n    widget = field.field.widget.get_context(\n        field.html_name, field.value() or field.initial, field.build_widget_attrs(attrs)\n    )  # -> {\"widget\": {\"name\": ...}}\n\n    context[\"widget\"] = widget[\"widget\"]\n\n    return context\n", "path": "src/registrar/templatetags/field_helpers.py"}]}