Andrii, The tests for `xs:gYear` and `xs:gYearMonth` now seem to work as we want them to.
I've implemented them for `minInclusive`, `maxInclusive`, `minExclusive`, and `maxExclusive`. Please let me know if it works as you expect it to. I've pushed this patched version to Bitbucket: https://bitbucket.org/dkuhlman/generateds Dave Earlier, Dave Kuhlman wrote: > Andrii, > > It seems like we should be generating a validator function that > looks like this: > > def validate_yearType(self, value): > # Validate type yearType, a restriction on xs:gYear. > if value is not None and Validate_simpletypes_: > if value < int(1900): > warnings_.warn('Value "%(value)s" does not match xsd > minInclusive restriction on yearType' % {"value" : value} ) > > An xs:gYear is being stored by the generated code as a string. That > is, its internal representation is a string. > > I guess that, effectively, we are saying that we will capture an > xs:gYear as a string, and will convert it to an integer when we need > an integer. > > 1. The validator method should do that conversion to integer when it > performs it's test. So, the test should like this: > > if int(value) < 1900: > > instead of: > > if value < 1900: > > 2. Or, maybe this would be better: > > if value < '1900': > > The reason that I suggest this second fix is because we should be > able to handle xs:gYearMonth types in addition to xs:gYear types. > For example: > > if value < '1900-01': > > That would work, don't you think? Does that seem reasonable to you? > And, I believe that will do the right thing on both Python 2 and > Python 3. > > Attached to a separate email is a version of generateDS.py that > contains this change (the 2nd one). > > Dave > > On Mon, May 13, 2019 at 03:18:11PM +0100, Andrii Iudin wrote: > > Dear Dave, > > > > We are in a process of moving to Python 3 and have stumbled upon the > > following problem. We have a field defined as > > <xs:element name="year" minOccurs="0"> > > <xs:simpleType> > > <xs:restriction base="xs:gYear"> > > <xs:minInclusive value="1900"/> > > </xs:restriction> > > </xs:simpleType> > > </xs:element> > > > > The generated code for it is > > def validate_yearType(self, value): > > # Validate type yearType, a restriction on xs:gYear. > > if value is not None and Validate_simpletypes_: > > if value < 1900: > > warnings_.warn('Value "%(value)s" does not match xsd > > minInclusive restriction on yearType' % {"value" : value} ) > > > > Which is fine in Python 2. However, when an XML file that contains > > <year>2017</year> > > > > is being processed in Python 3 the following error occurs: > > File "path/empiar.py", line 3784, in validate_yearType1 > > if value < 1900: > > TypeError: '<' not supported between instances of 'str' and 'int' > > > > Please could you advise on the way to solve this? > > > > Many thanks and best regards, > > Andrii > > > > > > _______________________________________________ > > generateds-users mailing list > > generateds-users@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/generateds-users -- Dave Kuhlman http://www.davekuhlman.org _______________________________________________ generateds-users mailing list generateds-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/generateds-users