Skip to content

Libdoc specs: Argument name, type and default should be stored separately #3578

Closed

Description

@pekkaklarck

Currently Libdoc spec contain argument information so that possible type and default value are embedded to argument name. For example, if we have a keyword like

def example(first, second: int=2):
    pass

its argument info is stored like

<arguments>
  <arg>first</arg>
  <arg>second: int=2</arg>
</arguments>

This is problematic if the consumer of the spec file wants to show only the argument name or is interested about the type or the default value for other reasons. Currently they need to split the argument info by using : and =, but this is extra work and also not fully safe as the default value and even the name can contain these characters as well. We need to store name, type and default separately but I'm not yet certain what's the best approach. Let's discuss about options in comments (or our Slack).

Related to this, we need to decide should we map the argument type info keywords provide to types we actually support. It is, fore example, possible to specify that an argument is an integer by using actual int type in Python, but also string Integer (case-insensitively) works in order to support dynamic API. Currently Libdoc spec files contain whatever the keyword provided and mapping to actually supported types is done at run time. Mapping types also in Libdoc spec files would have a benefit that spec consumers didn't need to support aliases like int and Integer. Not sure should this topic have its own issue.

Yet another thing to decide is showing varargs, kwargs and kw-only args. Currently we just have arguments like *varargs, **kws and * (kw-only separator) but could possibly specify this information somehow otherwise as well. That's highly related to deciding on the format how arguments are specified in general but probably needs a separate issue.

Activity

  1. added this to the v3.3 milestone on May 22, 2020
  2. pekkaklarck commented on May 22, 2020

    @pekkaklarck
    MemberAuthor

    One possibility how to separate name, type and default is grouping them together like this:

    <arguments>
      <arg>
        <name>first</name>
      </arg>
      <arg>
        <name>second</name>
        <type>int</type>
        <default>2</default>
      </arg>
    </arguments>
    

    Name and type could also be attributes, but default value can contain newlines so it either needs to be an element or its value must he encoded to be able to safely use it as an attribute.

    A problem with this approach is that it's quite badly backwards incompatible with the old format.

  3. pekkaklarck commented on May 22, 2020

    @pekkaklarck
    MemberAuthor

    Another alternative is listing names and then mapping names to types and defaults separately. There are many possibilities for handling this mapping, but this is one possibility:

    <arguments>
      <arg>first</arg>
      <arg>second</arg>
      <type for="second">int</type>
      <default for="second">2</default>
    </arguments>
    

    This approach is to some extend compatible with the old format but I'm not sure is that so important.

  4. Snooz82 commented on Sep 15, 2020

    @Snooz82
    Member

    Current plan is, that the default XML will be incompatible with the previous Version.
    It will become version 03.

    There is already Version 01 and 02 (doc/schema/libdoc.02.xsd)

    For backwards compatibility it shall be possible to generate legacyXML.

    If reading of legacy XML is really needed is not yet clear.
    legacy XML does not have all information the new libdoc model would require.
    However it could be possible to parse arguments like argname:Type =default so stay compatible.
    i wouldn’t assume that that is really needed.

    imho the only case where this would be relevant, that someone has a "old" XML file somewhere and wants to create a html out of it. But the Library itself is not there anymore...
    How realistic is this?

  5. pekkaklarck commented on Oct 20, 2020

    @pekkaklarck
    MemberAuthor

    Isn't this done now that #3720 has been merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions