Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP]: routinely add return statements to generators for inheritance #127

Closed
blaggacao opened this issue Sep 25, 2019 · 5 comments
Closed
Labels
stale PR/Issue without recent activity, it'll be soon closed automatically.

Comments

@blaggacao
Copy link

blaggacao commented Sep 25, 2019

Routinely add return statements on generators to ease inheritance / extension:

example:

    @api.model
    def _ubl_add_address(
            self, partner, node_name, parent_node, ns, version='2.1'):
        address = etree.SubElement(parent_node, ns['cac'] + node_name)
        ...
        return address

Then:

    @api.model
    def _ubl_add_address(
            self, partner, node_name, parent_node, ns, version='2.1'):
        address = super()._ubl_add_address(
            partner, node_name, parent_node, ns, version=version)

        id = etree.SubElement(
            address, ns['cbc'] + 'ID')
        id.text = 'MY-LOCALIZED-ID'
        ...
        return address
@blaggacao
Copy link
Author

/cc @Deiber

@astirpe
Copy link
Member

astirpe commented Sep 25, 2019

@blaggacao did you try if the following is working?

    @api.model
    def _ubl_add_address(
            self, partner, node_name, parent_node, ns, version='2.1'):
        super()._ubl_add_address(
            partner, node_name, parent_node, ns, version=version)
        address = etree.SubElement(parent_node, ns['cac'] + node_name)
        id = etree.SubElement(
            address, ns['cbc'] + 'ID')
        id.text = 'MY-LOCALIZED-ID'
        ...

@blaggacao
Copy link
Author

blaggacao commented Sep 26, 2019

@astirpe I can confirm your suggestion is NOT working: it indeed creates a sibling.

>>> root = CAC.Test()
>>> etree.SubElement(root, ns['cac'] + 'Foo')
<Element {urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2}Foo at 0x7fcd272a0708>
>>> etree.SubElement(root, ns['cac'] + 'Foo')
<Element {urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2}Foo at 0x7fcd272a0808>
>>> etree.tostring(root, pretty_print=True)
b'<cac:Test ...">
  <cac:Foo/>
  <cac:Foo/>
</cac:Test>
'

@blaggacao
Copy link
Author

blaggacao commented Sep 27, 2019

@astirpe However, I kind of have a faint Idea of an intention to use document accessors rather than passing around individual parts... Maybe in the Light of ElementMaker Syntax, this can be looked at from a different angle (I'm doing some syntax tests). See: #128

@blaggacao blaggacao changed the title [IMP]: routinely add return statements generators for inheritance [IMP]: routinely add return statements to generators for inheritance Sep 27, 2019
@github-actions
Copy link

There hasn't been any activity on this issue in the past 6 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this issue to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Dec 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale PR/Issue without recent activity, it'll be soon closed automatically.
Projects
None yet
Development

No branches or pull requests

2 participants