[lxml-dev] should _setElementValue add type attributes?
Stefan Behnel
stefan_ml at behnel.de
Tue Aug 28 09:16:57 CEST 2007
Hi Holger,
jholg at gmx.de wrote:
> For me, it begins to rather feel more natural to do:
>>>> # then
>>>> root.flag = True # real live python boolean object
>>>> root.flag
> True
>>>> root.flag.text
> "true"
>
> instead of
>>>> # now
>>>> root.flag = "true"
>>>> root.flag
> True
>
> which is, in the end, pretty much the same as
>>>> # now
>>>> root.three = "3"
>>>> root.three
> 3
>
> So, let's go for the auto-pytype-addition in _setElementValue, without special-casing, imo.
Fine, no special casing here. One more thing, though: we shouldn't store
Python type hints that were not registered as their instantiation wouldn't
work anyway. So I added a lookup before the attribute setter call.
So, the new rules are:
- what you put in comes back out (as long as the type is registered)
- for non-annotated XML data, type inference is used to determine the return
type (which may be ambiguous in some cases).
Simple enough, I'd say.
Stefan
More information about the lxml-dev
mailing list