@@ -259,3 +259,40 @@ class Model(BaseModel):
259259 # Check that annotation is the actual type, not Annotated[...]
260260 assert str (package ["Model.a" ].annotation ) == "int"
261261 assert str (package ["Model.b" ].annotation ) == "int"
262+
263+
264+ def test_ignore_private_attrs () -> None :
265+ """Test the extension ignores private attributes."""
266+ code = """
267+ from pydantic import BaseModel, PrivateAttr
268+
269+ class Model(BaseModel):
270+ field: str
271+ _private: str = PrivateAttr(default="secret")
272+ """
273+ with temporary_visited_package (
274+ "package" ,
275+ modules = {"__init__.py" : code },
276+ extensions = Extensions (PydanticExtension (schema = False )),
277+ ) as package :
278+ assert "pydantic-field" in package ["Model.field" ].labels
279+ assert "pydantic-field" not in package ["Model._private" ].labels
280+
281+
282+ def test_ignore_private_attrs_annotated () -> None :
283+ """Test the extension ignores private attributes with Annotated syntax."""
284+ code = """
285+ from pydantic import BaseModel, PrivateAttr
286+ from typing import Annotated
287+
288+ class Model(BaseModel):
289+ field: str
290+ _private: Annotated[str, PrivateAttr(default="secret")]
291+ """
292+ with temporary_visited_package (
293+ "package" ,
294+ modules = {"__init__.py" : code },
295+ extensions = Extensions (PydanticExtension (schema = False )),
296+ ) as package :
297+ assert "pydantic-field" in package ["Model.field" ].labels
298+ assert "pydantic-field" not in package ["Model._private" ].labels
0 commit comments