[lxml-dev] should _setElementValue add type attributes?
jholg at gmx.de
jholg at gmx.de
Mon Aug 27 13:43:10 CEST 2007
Hi,
> > I discussed this with Stefan before and I'm anxious to know if this is
> the
> > way to go (maybe as switchable behaviour), removing the need for a beast
> like
> > the discussed PT() factory, as well as making type behaviour arguably
> more
> > "straightforward", at the cost of auto-adding py:pytype attributes:
> [_setElementValue implementation that auto-adds type(RVAL).__name__ as
> py:pytype]
> > I'm +1 for that.
>
> Actually, you were the one who proposed it in the first place, so there's
> nothing to add to. :)
Yes, but I admit I was unsure then if this muddies the API by making
>>> root = objectify.Element("root")
>>> root.x = "3"
behave differently from
>>> root = objectify.fromstring("""<root><x>3</x></root>""")
Kind of losing sort of a symmetry.
But then again, we actually *do* have more information in the first case, namely the python type, so we should use it. Now I think that practicality beats purity here.
> > By making it switchable we could cater for those who don't
> > care about the types that much but who do not want to see any
> non-explicitly
> > created attributes.
>
> I dislike the idea of adding a switch here. We already add pytype
> attributes
> in a couple of places, so people who do not like it will have to
> deannotate()
> their XML anyway (or not use objectify...).
Right, there's also TREE attributes and stuff.
> I think that always adding a pytype will give us more predictable
> behaviour.
> On the other hand, we could just check if the pytype the type inference
> mechanism returns is the type of the value, and only add the attribute if
> that
> is not the case. What do you think? It would not work if you exchange
> annotated data with other machines that use different setups, but if you
> do
> that, you'd probably annotate everything by hand anyway.
I'd rather always add the pytype, then. I just think this is simpler. And if you want to exchange data with other machines, better xsiannotate() to fall back to XML standard types, or deannotate() and rely on type inference.
Holger
--
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kanns mit allen: http://www.gmx.net/de/go/multimessenger
More information about the lxml-dev
mailing list