# Buggy code
def empty_value_for_VR(VR, raw=False):
    """Return the value for an empty element for `VR`.

    .. versionadded:: 1.4

    The behavior of this property depends on the setting of
    :attr:`config.use_none_as_empty_value`. If that is set to ``True``,
    an empty value is represented by ``None`` (except for VR 'SQ'), otherwise
    it depends on `VR`. For text VRs (this includes 'AE', 'AS', 'CS', 'DA',
    'DT', 'LO', 'LT', 'PN', 'SH', 'ST', 'TM', 'UC', 'UI', 'UR' and 'UT') an
    empty string is used as empty value representation, for all other VRs
    except 'SQ', ``None``. For empty sequence values (VR 'SQ') an empty list
    is used in all cases.
    Note that this is used only if decoding the element - it is always
    possible to set the value to another empty value representation,
    which will be preserved during the element object lifetime.

    Parameters
    ----------
    VR : str
        The VR of the corresponding element.

    raw : bool
        If ``True``, returns the value for a :class:`RawDataElement`,
        otherwise for a :class:`DataElement`

    Returns
    -------
    str or bytes or None or list
        The value a data element with `VR` is assigned on decoding
        if it is empty.
    """
    if VR == "SQ":
        return []
    if config.use_none_as_empty_text_VR_value:
        return None
    if VR in (
        "AE",
        "AS",
        "CS",
        "DA",
        "DT",
        "LO",
        "LT",
        "PN",
        "SH",
        "ST",
        "TM",
        "UC",
        "UI",
        "UR",
        "UT",
    ):
        return b"" if raw else ""
    return None


# Traceback (TypeError)
Traceback (most recent call last):
File "C:\Program Files\Python37\lib\site-packages\pydicom\tag.py", line 30, in tag_in_exception
yield
File "C:\Program Files\Python37\lib\site-packages\pydicom\filewriter.py", line 555, in write_dataset
write_data_element(fp, dataset.get_item(tag), dataset_encoding)
File "C:\Program Files\Python37\lib\site-packages\pydicom\filewriter.py", line 463, in write_data_element
buffer.write(data_element.value)
TypeError: a bytes-like object is required, not 'list'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "./pydcmbug.py", line 7, in <module>
ds.save_as('bort.dcm')
File "C:\Program Files\Python37\lib\site-packages\pydicom\dataset.py", line 1810, in save_as
pydicom.dcmwrite(filename, self, write_like_original)
File "C:\Program Files\Python37\lib\site-packages\pydicom\filewriter.py", line 946, in dcmwrite
write_dataset(fp, get_item(dataset, slice(0x00010000, None)))
File "C:\Program Files\Python37\lib\site-packages\pydicom\filewriter.py", line 555, in write_dataset
write_data_element(fp, dataset.get_item(tag), dataset_encoding)
File "C:\Program Files\Python37\lib\contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "C:\Program Files\Python37\lib\site-packages\pydicom\tag.py", line 37, in tag_in_exception
raise type(ex)(msg)
TypeError: With tag (0040, 0275) got exception: a bytes-like object is required, not 'list'
Traceback (most recent call last):
File "C:\Program Files\Python37\lib\site-packages\pydicom\tag.py", line 30, in tag_in_exception
yield
File "C:\Program Files\Python37\lib\site-packages\pydicom\filewriter.py", line 555, in write_dataset
write_data_element(fp, dataset.get_item(tag), dataset_encoding)
File "C:\Program Files\Python37\lib\site-packages\pydicom\filewriter.py", line 463, in write_data_element
buffer.write(data_element.value)
TypeError: a bytes-like object is required, not 'list'

# Fixed code
def empty_value_for_VR(VR, raw=False):
    """Return the value for an empty element for `VR`.

    .. versionadded:: 1.4

    The behavior of this property depends on the setting of
    :attr:`config.use_none_as_empty_value`. If that is set to ``True``,
    an empty value is represented by ``None`` (except for VR 'SQ'), otherwise
    it depends on `VR`. For text VRs (this includes 'AE', 'AS', 'CS', 'DA',
    'DT', 'LO', 'LT', 'PN', 'SH', 'ST', 'TM', 'UC', 'UI', 'UR' and 'UT') an
    empty string is used as empty value representation, for all other VRs
    except 'SQ', ``None``. For empty sequence values (VR 'SQ') an empty list
    is used in all cases.
    Note that this is used only if decoding the element - it is always
    possible to set the value to another empty value representation,
    which will be preserved during the element object lifetime.

    Parameters
    ----------
    VR : str
        The VR of the corresponding element.

    raw : bool
        If ``True``, returns the value for a :class:`RawDataElement`,
        otherwise for a :class:`DataElement`

    Returns
    -------
    str or bytes or None or list
        The value a data element with `VR` is assigned on decoding
        if it is empty.
    """
    if VR == "SQ":
        return b"" if raw else []
    if config.use_none_as_empty_text_VR_value:
        return None
    if VR in (
        "AE",
        "AS",
        "CS",
        "DA",
        "DT",
        "LO",
        "LT",
        "PN",
        "SH",
        "ST",
        "TM",
        "UC",
        "UI",
        "UR",
        "UT",
    ):
        return b"" if raw else ""
    return None