@@ -121,55 +121,54 @@ Type annotations can be added as follows:
121121
122122 import attr
123123
124- @attr.s
124+ @attrs.define
125125 class A :
126- one: int = attr.ib() # Variable annotation (Python 3.6+)
127- two = attr.ib() # type : int # Type comment
128- three = attr.ib( type = int ) # type= argument
126+ one: int
127+ two: int = 7
128+ three: int = attrs.field( 8 )
129129
130- If you're using ``auto_attribs=True `` you must use variable annotations.
130+ If you're using ``auto_attribs=False `` you must use `` attrs.field ``:
131131
132132.. code-block :: python
133133
134- import attr
134+ import attrs
135135
136- @attr.s ( auto_attribs = True )
136+ @attrs.define
137137 class A :
138- one: int
139- two: int = 7
140- three: int = attr.ib( 8 )
138+ one: int = attrs.field() # Variable annotation (Python 3.6+)
139+ two = attrs.field() # type : int # Type comment
140+ three = attrs.field( type = int ) # type= argument
141141
142142 Typeshed has a couple of "white lie" annotations to make type checking
143- easier. :py:func: `attr.ib ` and :py:class: `attr .Factory ` actually return objects, but the
143+ easier. :py:func: `attrs.field ` and :py:class: `attrs .Factory ` actually return objects, but the
144144annotation says these return the types that they expect to be assigned to.
145145That enables this to work:
146146
147147.. code-block :: python
148148
149- import attr
150- from typing import Dict
149+ import attrs
151150
152- @attr.s ( auto_attribs = True )
151+ @attrs.define
153152 class A :
154- one: int = attr.ib (8 )
155- two: Dict [str , str ] = attr .Factory(dict )
156- bad: str = attr.ib (16 ) # Error: can't assign int to str
153+ one: int = attrs.field (8 )
154+ two: dict [str , str ] = attrs .Factory(dict )
155+ bad: str = attrs.field (16 ) # Error: can't assign int to str
157156
158157 Caveats/Known Issues
159158====================
160159
161160* The detection of attr classes and attributes works by function name only.
162161 This means that if you have your own helper functions that, for example,
163- ``return attr.ib () `` mypy will not see them.
162+ ``return attrs.field () `` mypy will not see them.
164163
165164* All boolean arguments that mypy cares about must be literal ``True `` or ``False ``.
166165 e.g the following will not work:
167166
168167 .. code-block :: python
169168
170- import attr
169+ import attrs
171170 YES = True
172- @attr.s (init = YES )
171+ @attrs.define (init = YES )
173172 class A :
174173 ...
175174
0 commit comments