I have written an xsd parser to generate python classes. I also have
written a utility to read in an xml file to populate the python classes.
As well as a utility to write xml from the python classes thus generated.
For example the code below that I include here shows a small sample of the
generated code.
The __annotations__ for these are very easy to use by the utility code for
doing their job.

Using the typing list[x] and tuple[a,b] do not work as well as
- [x] instead of list[x]
- (a, b) instead of tuple(a, b)

I seem to feel list[x] and tuple[a,b] are far more non Python, requiring
having to parse the string they return in a complicated way.

Looping through the annotations to get the field types it's easy to test
for list or tuple and then get the field type for the list or tuple and the
usage for the tuple.

I have been using Python from version 1.6 and have been involved in writing
and generating tons of lines of Python.

ATTRIB, PSEUDO, ASIS = range(3)

class RecordType:
    isNew: str
    column: (str,ATTRIB)
    whizz: (str,PSEUDO)
    def __init__(self):
        self.isNew = ''
        self.whizz = ''
        self.column = ''

class MsgTableType:
    record: [RecordType]
    def __init__(self):
        self.record = []

rt = RecordType()
for annote in rt.__annotations__:
    print (annote, type(rt.__annotations__[annote]))

mtt = MsgTableType()
for annote in mtt.__annotations__:
    print (annote, type(mtt.__annotations__[annote]))
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/ANSJXQTUQDGADZRLAV5YFRU74NHUBVBL/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to