manusimidt / py-xbrl

Python-based parser for parsing XBRL and iXBRL files
https://py-xbrl.readthedocs.io/en/latest/
GNU General Public License v3.0
100 stars 37 forks source link

Need path or reference to source file of a Linkbase #102

Closed ajmedeio closed 1 year ago

ajmedeio commented 1 year ago

@manusimidt I need the Linkbase class to have a reference to the source file it was parsed from. This enables me to link between my own parsed Linkbase and the libraries' parsed Linkbases.

The work to implement this feature:

This requires an extra property added to the Linkbase constructor with default value of None (for backwards compatibility):

class Linkbase:
    def __init__(self, extended_links: List[ExtendedLink], linkbase_type: LinkbaseType, linkbase_url: str = None) -> None:
        # ... (initialization of links and type) ...
        self.linkbase_url = linkbase_url

src

And finally, notice the last argument of the return statement here:

def parse_linkbase(linkbase_path: str, linkbase_type: LinkbaseType, linkbase_url: str or None = None) -> Linkbase:
    # ... (implementation here) ...
    return Linkbase(extended_links, linkbase_type, linkbase_url if linkbase_url else linkbase_path)

src

If you see an alternative approach please don't hesitate to clarify.

Explanation of change

The result of this change is linkbases have an additional property named linkbase_url which is an href if parsed from the internet or an absolute path on the filesystem if parsed from a local file.

manusimidt commented 1 year ago

Ok seems like a reasonable change. I will just probably call it 'linkbase_uri' instead of 'linkbase_url'. I have made this distinction before to differentiate between real URL's and ones that can be both a URL and a path.

ajmedeio commented 1 year ago

Beautiful, you're a pleasure to work with.

Cheers!