MCPcopy
hub / github.com/pydantic/pydantic / test_class_var_as_string

Function test_class_var_as_string

tests/test_forward_ref.py:553–576  ·  view source on GitHub ↗
(create_module)

Source from the content-addressed store, hash-verified

551
552
553def test_class_var_as_string(create_module):
554 module = create_module(
555 # language=Python
556 """
557from __future__ import annotations
558from typing import Annotated, ClassVar, ClassVar as CV
559from pydantic import BaseModel
560
561class Model(BaseModel):
562 a: ClassVar[int]
563 _b: ClassVar[int]
564 _c: ClassVar[Forward]
565 _d: Annotated[ClassVar[int], ...]
566 _e: CV[int]
567 _f: Annotated[CV[int], ...]
568 # Doesn't work as of today:
569 # _g: CV[Forward]
570
571Forward = int
572"""
573 )
574
575 assert module.Model.__class_vars__ == {'a', '_b', '_c', '_d', '_e', '_f'}
576 assert module.Model.__private_attributes__ == {}
577
578
579def test_private_attr_annotation_not_evaluated() -> None:

Callers

nothing calls this directly

Calls 1

create_moduleFunction · 0.85

Tested by

no test coverage detected