I've added back in the pyxb-users list. Again, though, a better forum for
questions like this is is
https://sourceforge.net/p/pyxb/discussion/956708because in practice
that's where most "how does this work" things end up.
Very few people subscribe to this list.
The test I would probably use is simply:
if element.subelement:
# There's a subelement, whether it's one or many.
pass
relying on the fact that an empty list and None both evaluate to false.
The test case for trac/218 validates this. There's a maintainability case
to be made for being explicit that the content model expects multiple
values; if that's persuasive then yes, do "0 < len(element.subelement)".
The failed comparison to None won't produce a new release, since it's not a
valid comparison. However the fact that ordered comparison of non-empty
lists is going to be wrong might if other people start running into it.
I'm going to wait for now.
It's a pain to add things to the python3 branch (have to switch branches,
regenerate the entire world including all bindings, and re-run all the
tests, then move back and regenerate the world again) so though that'll
happen occasionally I'm not going to do it as quickly as getting a patch
onto the supported next branch. When I do, as I warned before,
python3/next will be rebased, rather than having a new commit added to it.
I have done that now, though, since the repository python3/next pre-dated
the 1.2.3 release which was a bit too misleading.
Peter
On Thu, Sep 19, 2013 at 11:57 PM, Nathan Robertson <nath...@nathanr.net>wrote:
> Awesome, thanks Peter. I just wrote some tests to confirm my understanding
> of "attributes with multiplicity greater than 1 default to an empty list"
> and confirmed what you're saying. Indeed "<?xml version="1.0"
> ?><ns1:topLevel xmlns:ns1="http://nathanr.net/pyxbtest"/>" (ie. no
> <item>'s in the list) does indeed give a not None obj.item, meaning an
> empty list object, as you suggest.
>
> Thanks again for your help. It sounds like we're testing a condition that
> we shouldn't be - we should be testing "len(list) > 0" rather than "list !=
> None and len(list) > 0". We're just about to do a release, so we'll revert
> to 1.2.2 until post-release, then do a code audit to make sure that we
> remove instances of "list != None", and after that upgrade to 1.2.3 again.
>
> Sorry - I meant to cc: the list as well. I hit "reply" rather than "reply
> all". Apologies.
>
> I'm assuming the above bug won't trigger a 1.2.4 release? Or are you
> intending on a 1.2.4 just to include the trac/218 regression fix? Has that
> fix been committed to the Python 3.x next branch as well?
>
> Regards,
> Nathan.
>
>
>
> On 20 September 2013 13:06, Peter Bigot <big...@acm.org> wrote:
>
>> Please report bugs on trac (preferably) or on the Help forum; sending
>> them to me directly keeps others from benefiting from any resulting
>> discussion.
>>
>> Yes, this is a bug, now entered as trac/218, and a fix committed to the
>> next branch.
>>
>> FWIW, obj.items would never have compared equal to or identical to None.
>> Element attributes with multiplicity greater than 1 default to an empty
>> list (or, now, a wrapper object that satisfies collections.MutableSequence
>> while ensuring members are valid for the list member type).
>>
>> Peter
>>
>>
>> On Thu, Sep 19, 2013 at 9:29 PM, Nathan Robertson <nath...@nathanr.net>wrote:
>>
>>> Hi Peter,
>>>
>>> I think there is a regression in the way lists work in 1.2.3. It would
>>> appear that in 1.2.3 (list_obj != None) doesn't work the way it used to,
>>> and (list_obj != None) and (list_obj is not None) are not the same. The two
>>> were equivalent in 1.2.2. Below is a test case which shows the difference.
>>> I'm using the release version of 1.2.2 and release version of 1.2.3 on
>>> Fedora 19 x64 with Python 2.7.5.
>>>
>>> The test case schema (test_schema.xsd) is:
>>> -----
>>> <?xml version="1.0"?>
>>> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>>> targetNamespace="http://nathanr.net/pyxbtest" xmlns:zenkai="
>>> http://nathanr.net/pyxbtest">
>>> <xsd:element name="topLevel">
>>> <xsd:complexType>
>>> <xsd:sequence>
>>> <xsd:element name="item" type="xsd:string"
>>> maxOccurs="unbounded"/>
>>> </xsd:sequence>
>>> </xsd:complexType>
>>> </xsd:element>
>>> </xsd:schema>
>>> -----
>>>
>>> The test case script is:
>>> -----
>>> import pyxb
>>> import test_schema
>>>
>>> print("This is PyXB version {}".format(pyxb.__version__))
>>> print("Bindings built with pyxbgen version
>>> {}".format(test_schema._PyXBVersion))
>>>
>>> tl = test_schema.topLevel()
>>> for x in ["a", "b", "c", "d"]:
>>> tl.item.append(x)
>>> input = tl.toxml()
>>> print("Input XML will be: {}".format(input))
>>>
>>> obj = test_schema.CreateFromDocument(input)
>>> print("Type of object is: {}".format(type(obj)))
>>> print("Length of list is: {}".format(len(obj.item)))
>>> print("obj != None? {}".format(obj.item != None))
>>> print("obj is not None? {}".format(obj.item is not None))
>>> -----
>>>
>>> Output with 1.2.3:
>>> -----
>>> (pyenv-zenkai)[nathanr@emelin pyxb-broken-null-list]$ ./test.sh
>>> Python for http://nathanr.net/pyxbtest requires 1 modules
>>> This is PyXB version 1.2.3
>>> Bindings built with pyxbgen version 1.2.3
>>> Input XML will be: <?xml version="1.0" ?><ns1:topLevel xmlns:ns1="
>>> http://nathanr.net/pyxbtest
>>> "><item>a</item><item>b</item><item>c</item><item>d</item></ns1:topLevel>
>>> Type of object is: <class 'test_schema.CTD_ANON'>
>>> Length of list is: 4
>>> obj != None? False
>>> obj is not None? True
>>> (pyenv-zenkai)[nathanr@emelin pyxb-broken-null-list]$
>>> -----
>>>
>>> Output with 1.2.2:
>>> -----
>>> (pyenv-zenkai-pyxb-1.2.2)[nathanr@emelin pyxb-broken-null-list]$
>>> ./test.sh
>>> Python for http://nathanr.net/pyxbtest requires 1 modules
>>> This is PyXB version 1.2.2
>>> Bindings built with pyxbgen version 1.2.2
>>> Input XML will be: <?xml version="1.0" ?><ns1:topLevel xmlns:ns1="
>>> http://nathanr.net/pyxbtest
>>> "><item>a</item><item>b</item><item>c</item><item>d</item></ns1:topLevel>
>>> Type of object is: <class 'test_schema.CTD_ANON'>
>>> Length of list is: 4
>>> obj != None? True
>>> obj is not None? True
>>> (pyenv-zenkai-pyxb-1.2.2)[nathanr@emelin pyxb-broken-null-list]$
>>> -----
>>>
>>> As you can see, there are four items in the "obj" list. I believe 1.2.2
>>> implemented the "obj != None" check correctly, and the 1.2.3 behaviour is a
>>> regression. Could you confirm this and then I'll open a Trac ticket for the
>>> issue?
>>>
>>> Regards,
>>> Nathan.
>>>
>>>
>>>
>>> On 19 September 2013 02:07, Peter Bigot <big...@acm.org> wrote:
>>>
>>>> 1.2.3 (18 Sep 2013)
>>>>
>>>> This is primarily a bug-fix and clean-up release. One new feature is
>>>> that
>>>> starting with this release a Python 3 compatible version of PyXB will be
>>>> available in the git repository. For this version, it may be obtained
>>>> by::
>>>>
>>>> git clone -b python3/pyxb-1.2.3
>>>> git://git.code.sf.net/p/pyxb/codepyxb3-1.2.3
>>>>
>>>> The Python 3 code in this branch is created by automatic conversion of
>>>> the
>>>> Python 2 code using the maintainer/2to3 script. While not officially
>>>> supported until PyXB 1.3.0, Python 3 appears to work correctly with this
>>>> version.
>>>>
>>>> Behavioral changes:
>>>>
>>>> - PyXB 1.2.1 automatically filled in the content of fixed elements.
>>>> This
>>>> generated invalid documents when the particular element should have
>>>> been
>>>> absent for some content. The feature has been removed so fixed
>>>> elements
>>>> initialize to absent just like every other element.
>>>>
>>>> - The former `--pre-load-archives` option to pyxbgen has been removed
>>>> and
>>>> replaced by :ref:`pyxbgen--import-augmentable-namespace` which has
>>>> more
>>>> consistent semantics. Schema import directives related to a
>>>> non-augmentable
>>>> namespace (one for which the referenced option has not been provided)
>>>> will
>>>> be ignored if content for the namespace can be located in any archive
>>>> or
>>>> builtin.
>>>>
>>>> - Generating DOM (or XML) expressions of bindings that were created by
>>>> type
>>>> constructors and not associated with elements now cause an exception
>>>> to be
>>>> raised rather than mis-using the type name as though it were a valid
>>>> element
>>>> tag.
>>>>
>>>> Code cleanup:
>>>>
>>>> - Trailing whitespace throughout the source has been removed to
>>>> decrease git
>>>> complaints and non-reproducible patches.
>>>> - Several coding practices that would not work under Python3 have been
>>>> replaced with new solutions.
>>>>
>>>> The following reported `defects/enhancements
>>>> <http://sourceforge.net/apps/trac/pyxb/>`_ have been addressed:
>>>>
>>>> - Fix DOM style handling of xsi:type attribute. :ticket:`166`
>>>> - Fix problems with nillable simple types. :ticket:`200`
>>>> - Fix problems inserting into plural element attributes. :ticket:`201`
>>>> - Correct namespace-qualified attributes. :ticket:`202`
>>>> - Eliminate automatic derivation of XML element tag from binding type
>>>> when
>>>> converting an element-free instance to DOM. :ticket:`203`
>>>> - Eliminate default to fixed value for elements. :ticket:`204`
>>>> - Re-word exception when element content was incompatible with fixed
>>>> value.
>>>> :ticket:`205`
>>>> - Fix the aslocal() method for xs:dateTime values with non-UTC
>>>> timezones.
>>>> :ticket:`206`
>>>> - Fix values for restricted duration ranges in pickled data such as
>>>> namespace
>>>> archives. :ticket:`207`
>>>> - Correct the interpretation of QName-valued base and similar
>>>> attributes with
>>>> respect to in-scope namespace declarations. :ticket:`208`
>>>> - Rework how to specify that imported namespaces should be processed to
>>>> extend
>>>> the content model. :ticket:`209`
>>>> - Removed redundant code in pyxbgen relevant to
>>>> :ref:`pyxbgen--wsdl-location`. :ticket:`210`
>>>> - Refine diagnostics when an element with simple type appears in a
>>>> context
>>>> that expects non-element content. :ticket:`211`
>>>> - Add :api:`pyxb.NonElementContent` to simplify access to non-element
>>>> content
>>>> in a mixed-content instance. :ticket:`212`
>>>> - Convert assert failures to diagnostic exceptions when generating DOM
>>>> expressions of complex types with simple content where the content is
>>>> missing. :ticket:`213`
>>>> - Ensure attribute values are converted from lexical space to value
>>>> space when
>>>> assigned from an XML representation. :ticket:`216`
>>>>
>>>>
>>>>
>>>> ------------------------------------------------------------------------------
>>>> LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
>>>> 1,500+ hours of tutorials including VisualStudio 2012, Windows 8,
>>>> SharePoint
>>>> 2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack
>>>> includes
>>>> Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13.
>>>>
>>>> http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk
>>>> _______________________________________________
>>>> pyxb-users mailing list
>>>> pyxb-users@lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/pyxb-users
>>>>
>>>>
>>>
>>
>
------------------------------------------------------------------------------
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13.
http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk
_______________________________________________
pyxb-users mailing list
pyxb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyxb-users