Skip to content

Commit 118ff3e

Browse files
committed
updated
1 parent 73d3f9f commit 118ff3e

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

docs/init.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ Even if you're not using this feature, it's important to be aware of it because
9090
... _1: int
9191
Traceback (most recent call last):
9292
...
93-
SyntaxError: invalid syntax
93+
TypeError: Invalid initialization alias '1' for attribute '_1'. Aliases must be valid Python identifiers.
94+
9495
```
9596

9697
In this case a valid attribute name `_1` got transformed into an invalid argument name `1`.
@@ -251,10 +252,7 @@ ValueError: 'x' has to be smaller than 'y'!
251252
... x = field(validator=attrs.validators.instance_of(int))
252253
>>> C(42)
253254
C(x=42)
254-
>>> C("42")
255-
Traceback (most recent call last):
256-
...
257-
TypeError: ("'x' must be <type 'int'> (got '42' that is a <type 'str'>).", Attribute(name='x', default=NOTHING, factory=NOTHING, validator=<instance_of validator for type <type 'int'>>, type=None), <type 'int'>, '42')
255+
TypeError: ("'x' must be <class 'int'> (got '42' that is a <class 'str'>).", Attribute(name='x', ..., alias='x'), <class 'int'>, '42')
258256
```
259257

260258
Of course you can mix and match the two approaches at your convenience.
@@ -270,10 +268,7 @@ If you use both ways to define validators for an attribute, they are both ran:
270268
... raise ValueError("value out of bounds")
271269
>>> C(128)
272270
C(x=128)
273-
>>> C("128")
274-
Traceback (most recent call last):
275-
...
276-
TypeError: ("'x' must be <class 'int'> (got '128' that is a <class 'str'>).", Attribute(name='x', default=NOTHING, validator=[<instance_of validator for type <class 'int'>>, <function fits_byte at 0x10fd7a0d0>], repr=True, cmp=True, hash=True, init=True, metadata=mappingproxy({}), type=None, converter=None), <class 'int'>, '128')
271+
TypeError: ("'x' must be <class 'int'> (got '128' that is a <class 'str'>).", Attribute(name='x', ..., alias='x'), <class 'int'>, '128')
277272
>>> C(256)
278273
Traceback (most recent call last):
279274
...
@@ -290,7 +285,7 @@ C(x='128')
290285
>>> C("128")
291286
Traceback (most recent call last):
292287
...
293-
TypeError: ("'x' must be <class 'int'> (got '128' that is a <class 'str'>).", Attribute(name='x', default=NOTHING, validator=[<instance_of validator for type <class 'int'>>, <function fits_byte at 0x10fd7a0d0>], repr=True, cmp=True, hash=True, init=True, metadata=mappingproxy({}), type=None, converter=None), <class 'int'>, '128')
288+
TypeError: ("'x' must be <class 'int'> (got '128' that is a <class 'str'>).", Attribute(name='x', ..., alias='x'), <class 'int'>, '128')
294289
```
295290

296291
... or within a context manager:
@@ -302,7 +297,7 @@ C(x='128')
302297
>>> C("128")
303298
Traceback (most recent call last):
304299
...
305-
TypeError: ("'x' must be <class 'int'> (got '128' that is a <class 'str'>).", Attribute(name='x', default=NOTHING, validator=[<instance_of validator for type <class 'int'>>, <function fits_byte at 0x10fd7a0d0>], repr=True, cmp=True, hash=True, init=True, metadata=mappingproxy({}), type=None, converter=None), <class 'int'>, '128')
300+
TypeError: ("'x' must be <class 'int'> (got '128' that is a <class 'str'>).", Attribute(name='x', ..., alias='x'), <class 'int'>, '128')
306301
```
307302

308303
(converters)=

0 commit comments

Comments
 (0)