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

[Python] Generated namedtuple types have unsat docstrings. #371

Closed
tseaver opened this issue Mar 19, 2019 · 5 comments
Closed

[Python] Generated namedtuple types have unsat docstrings. #371

tseaver opened this issue Mar 19, 2019 · 5 comments
Assignees
Labels
🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@tseaver
Copy link
Contributor

tseaver commented Mar 19, 2019

From: googleapis/google-cloud-python#7043

The members of a collections.namedtuple have no semantic information in their docstrings:

>>> import collections
>>> Foo = collections.namedtuple("Foo", ["bar", "baz", "qux"], verbose=True)
class Foo(tuple):
    'Foo(bar, baz, qux)'

    __slots__ = ()

    _fields = ('bar', 'baz', 'qux')

    def __new__(_cls, bar, baz, qux):
        'Create new instance of Foo(bar, baz, qux)'
        return _tuple.__new__(_cls, (bar, baz, qux))

    @classmethod
    def _make(cls, iterable, new=tuple.__new__, len=len):
        'Make a new Foo object from a sequence or iterable'
        result = new(cls, iterable)
        if len(result) != 3:
            raise TypeError('Expected 3 arguments, got %d' % len(result))
        return result

    def __repr__(self):
        'Return a nicely formatted representation string'
        return 'Foo(bar=%r, baz=%r, qux=%r)' % self

    def _asdict(self):
        'Return a new OrderedDict which maps field names to their values'
        return OrderedDict(zip(self._fields, self))

    def _replace(_self, **kwds):
        'Return a new Foo object replacing specified fields with new values'
        result = _self._make(map(kwds.pop, ('bar', 'baz', 'qux'), _self))
        if kwds:
            raise ValueError('Got unexpected field names: %r' % kwds.keys())
        return result

    def __getnewargs__(self):
        'Return self as a plain tuple.  Used by copy and pickle.'
        return tuple(self)

    __dict__ = _property(_asdict)

    def __getstate__(self):
        'Exclude the OrderedDict from pickling'
        pass

    bar = _property(_itemgetter(0), doc='Alias for field number 0')

    baz = _property(_itemgetter(1), doc='Alias for field number 1')

    qux = _property(_itemgetter(2), doc='Alias for field number 2')
@michaelbausor
Copy link
Contributor

@lukesneeringer Assigning to you, but please feel free to reassign. Also, I was unsure whether this would be fixed in gapic-generator, or if the fix will be provided as part of gapic-generator-python.

@plamut
Copy link
Contributor

plamut commented Jun 12, 2019

FWIW, I created a pull request that handles this via the synth file. We might want to close this issue.

@tseaver
Copy link
Contributor Author

tseaver commented Jun 19, 2019

@plamut Rather than adding those docstrings in synth.py, it would be preferable to have the generator use whatever comments are in the .proto files for the enums to generate them upstream.

@plamut
Copy link
Contributor

plamut commented Jun 19, 2019

@tseaver After working with synth for a bit, I cannot disagree - I'll be happy to remove that part form it once the generator is updated.

@yihanzhen yihanzhen transferred this issue from googleapis/gapic-generator Apr 9, 2020
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Apr 9, 2020
@software-dov
Copy link
Contributor

Microgenerator does not use namedtuples, no longer relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

6 participants