You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After reading through the documentation it is still unclear to me what the type parameter of attr.ib does. Is it only for type hinting? There is no mention of how it is leveraged by the validator and converter parameters. It seems to be a mystery field with no relationship to any other feature or code.
Given the following code:
importattr@attr.sclassFoo:
bar=attr.ib(type=str)
I would expect the following to not be valid: foo = Foo(12)
I also expect the following to not be valid: attr.validate(foo)
Since both are "valid", what value did that type parameter give me?
My expectation would be that when the type= field is provided a default isinstance() validator is applied. Additionally, it wouldn't be a stretch to assume a default converter is applied.
importattr@attr.sclassBar:
x=attr.ib(type=int)
One might expect: bar = Bar('12') to be valid since int('12') is valid.
The text was updated successfully, but these errors were encountered:
After reading through the documentation it is still unclear to me what the
type
parameter ofattr.ib
does. Is it only for type hinting? There is no mention of how it is leveraged by thevalidator
andconverter
parameters. It seems to be a mystery field with no relationship to any other feature or code.Given the following code:
I would expect the following to not be valid:
foo = Foo(12)
I also expect the following to not be valid:
attr.validate(foo)
Since both are "valid", what value did that type parameter give me?
My expectation would be that when the
type=
field is provided a defaultisinstance()
validator is applied. Additionally, it wouldn't be a stretch to assume a default converter is applied.One might expect:
bar = Bar('12')
to be valid sinceint('12')
is valid.The text was updated successfully, but these errors were encountered: