Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #9270
Closed
Open
Issue created Apr 15, 2021 by Administrator@rootContributor1 of 6 checklist items completed1/6 checklist items

[BUG][PYTHON-LEGACY] DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() or inspect.getfullargspec()

Created by: johnthagen

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The python-legacy generator should not produce DeprecationWarning's on supported versions of Python (e.g. Python 3.6-3.9).

This change seems to have happened between 4.3.1 and 5.1.0

The usage of inspect.getargspec() should be avoided on Python 3.

openapi-generator version

5.1.0

OpenAPI declaration file content or url
Generation Details
npx @openapitools/openapi-generator-cli generate \
  --input-spec http://localhost:8000/rest/swagger.json \
  --generator-name python-legacy --output . \
  --additional-properties=generateSourceCodeOnly=true
Steps to reproduce

Stack trace of the DeprecationWarning:

openapi_client/models/layer_nested.py:245: in convert
    args = inspect.getargspec(x.to_dict).args
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

func = <[DeprecationWarning('inspect.getargspec() is deprecated since Python 3.0, use inspect.signature() or inspect.getfullargspec()') raised in repr()] method object at 0x138e63740>

    def getargspec(func):
        """Get the names and default values of a function's parameters.
    
        A tuple of four things is returned: (args, varargs, keywords, defaults).
        'args' is a list of the argument names, including keyword-only argument names.
        'varargs' and 'keywords' are the names of the * and ** parameters or None.
        'defaults' is an n-tuple of the default values of the last n parameters.
    
        This function is deprecated, as it does not support annotations or
        keyword-only parameters and will raise ValueError if either is present
        on the supplied callable.
    
        For a more structured introspection API, use inspect.signature() instead.
    
        Alternatively, use getfullargspec() for an API with a similar namedtuple
        based interface, but full support for annotations and keyword-only
        parameters.
    
        Deprecated since Python 3.5, use `inspect.getfullargspec()`.
        """
>       warnings.warn("inspect.getargspec() is deprecated since Python 3.0, "
                      "use inspect.signature() or inspect.getfullargspec()",
                      DeprecationWarning, stacklevel=2)
E       DeprecationWarning: inspect.getargspec() is deprecated since Python 3.0, use inspect.signature() or inspect.getfullargspec()

/usr/local/Cellar/python@3.9/3.9.1_6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/inspect.py:1116: DeprecationWarning

The generated method using the deprecated function:

    def to_dict(self, serialize=False):
        """Returns the model properties as a dict"""
        result = {}

        def convert(x):
            if hasattr(x, "to_dict"):
                args = inspect.getargspec(x.to_dict).args
                if len(args) == 1:
                    return x.to_dict()
                else:
                    return x.to_dict(serialize)
            else:
                return x

        for attr, _ in six.iteritems(self.openapi_types):
            value = getattr(self, attr)
            attr = self.attribute_map.get(attr, attr) if serialize else attr
            if isinstance(value, list):
                result[attr] = list(map(lambda x: convert(x), value))
            elif isinstance(value, dict):
                result[attr] = dict(map(lambda item: (item[0], convert(item[1])), value.items()))
            else:
                result[attr] = convert(value)

        return result
Related issues/PRs

#1719 (closed)

Suggest a fix

Use inspect.signature() or inspect.getfullargspec()

Assignee
Assign to
Time tracking