harbor run -t openthoughts/tasktrove-swegym-tasks-patched-validated-v2-swegym-1075harbor download openthoughts/tasktrove-swegym-tasks-patched-validated-v2-swegym-1075pydantic/pydantic742c39150f3bcd695420ce5a631e36cc365164f1pydantic__pydantic-58972.04cd /testbed
git clone https://github.com/pydantic/pydantic.git repo
cd repo
git checkout 742c39150f3bcd695420ce5a631e36cc365164f1
# Activate environment
source /opt/miniconda3/bin/activate
conda activate testbed
# Install dependencies
pip install pdm && pdm install
Error on deleting an attribute of a Model having a PrivateAttr defined
main branch, or equivalentIf a Model has a PrivateAttr defined deleting a regular field of its instance results in an AttributeError.
from pydantic import BaseModel, PrivateAttr
class Model(BaseModel):
some_field: str
m = Model(some_field='value')
del m.some_field # this works
class Model(BaseModel):
_private_attr: int = PrivateAttr(default=1)
some_field: str
m = Model(some_field='value')
del m.some_field # this fails
pydantic version: 2.0a4
pydantic-core version: 0.36.0 release build profile
python version: 3.11.3 (main, May 24 2023, 00:00:00) [GCC 13.1.1 20230511 (Red Hat 13.1.1-2)]
platform: Linux-6.2.15-300.fc38.x86_64-x86_64-with-glibc2.37
optional deps. installed: ['devtools', 'email-validator', 'typing-extensions']
tests/test_create_model.py::test_private_attr_set_name_do_not_crash_if_not_callabletests/test_create_model.py::test_create_model_protected_namespace_defaulttests/test_create_model.py::test_del_model_attr_errortests/test_create_model.py::test_config_and_basetests/test_create_model.py::test_create_model_pickletests/test_create_model.py::test_inheritancetests/test_create_model.py::test_create_model_field_and_model_titletests/test_create_model.py::test_repeat_base_usagetests/test_create_model.py::test_create_model_usagetests/test_create_model.py::test_del_model_attrtests/test_create_model.py::test_private_attr_set_nametests/test_create_model.py::test_del_model_attr_with_privat_attrs_twice_errortests/test_create_model.py::test_inheritance_validatorstests/test_create_model.py::test_create_model_tuple_3tests/test_create_model.py::test_del_model_attr_with_privat_attrs_errortests/test_create_model.py::test_dynamic_and_statictests/test_create_model.py::test_private_descriptors[True-object]tests/test_create_model.py::test_create_model_custom_protected_namespacetests/test_create_model.py::test_create_model_with_slotstests/test_create_model.py::test_inheritance_validators_alwaystests/test_create_model.py::test_create_modeltests/test_create_model.py::test_create_model_multiple_protected_namespacetests/test_create_model.py::test_private_descriptors[False-ModelPrivateAttr]tests/test_create_model.py::test_create_model_tupletests/test_create_model.py::test_private_descriptors[True-ModelPrivateAttr]tests/test_create_model.py::test_create_model_field_descriptiontests/test_create_model.py::test_custom_configtests/test_create_model.py::test_inheritance_validators_alltests/test_create_model.py::test_private_descriptors[False-object]tests/test_create_model.py::test_field_wrong_tupletests/test_create_model.py::test_custom_config_extrastests/test_create_model.py::test_invalid_nametests/test_create_model.py::test_custom_config_inheritstests/test_create_model.py::test_funky_nametests/test_create_model.py::test_create_model_non_annotatedtests/test_create_model.py::test_del_model_attr_with_privat_attrsApply code changes directly inside /testbed/repo and use pytest to run any of the above test targets. Focus on making the failing tests succeed without regressing the existing passing suite.