About the Pinttrs interface#


  • As of Pinttrs v23.2.0, using the modern interface pinttrs.field() is recommended. The classic interface pinttr.ib() is still available.

  • As of Pinttrs v23.2.0, using import attrs is recommended. The classic import attr is still supported.

Pinttrs initially mimicked the attrs import and interface policies so that using it would feel natural to attrs users. Therefore, the code was located in a pinttr package, and the main interface was pinttr.ib(). Typically, a field definition would look like this:

>>> import attr, pinttr
>>> ureg = pinttr.get_unit_registry()
>>> @attr.s
... class MyClass:
...     field = pinttr.ib(units=ureg.m)
>>> MyClass(1.0)
MyClass(field=1.0 m)

As mentioned in the documentation, the attrs interface then evolved. Pinttrs followed the movement in order to provide similar expressiveness. Consequently, we introduced pinttrs.field and the pinttrs package:

>>> import attrs, pinttrs
>>> @attrs.define
... class MyClass:
...     field = pinttrs.field(units=ureg.m)
>>> MyClass(1.0)
MyClass(field=1.0 m)

This interface is recommended, but the classic one is still available and supported.