MCPcopy
hub / github.com/python-attrs/attrs / test_generics

Method test_generics

tests/test_make.py:1609–1625  ·  tests/test_make.py::TestFields.test_generics

Fields work with generic classes.

(self)

Source from the content-addressed store, hash-verified

1607 assert getattr(fields(C), attribute.name) is attribute
1608
1609 def test_generics(self):
1610 class="st">"""
1611 Fields work with generic classes.
1612 class="st">"""
1613 T = TypeVar(class="st">"T")
1614
1615 @attr.define
1616 class A(Generic[T]):
1617 a: T
1618
1619 assert len(fields(A)) == 1
1620 assert fields(A).a.name == class="st">"a"
1621 assert fields(A).a.default is attr.NOTHING
1622
1623 assert len(fields(A[str])) == 1
1624 assert fields(A[str]).a.name == class="st">"a"
1625 assert fields(A[str]).a.default is attr.NOTHING
1626
1627
1628class TestFieldsDict:

Callers

nothing calls this directly

Calls 1

fieldsFunction · 0.90

Tested by

no test coverage detected