OpenAPITools / OpenAPITools/openapi-generator

[BUG][Python3.7][openapi-generator-cli] ImportError: cannot import name 'GenericMeta' from 'typing'

Open
#7,010 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

When running python client package in python 3.7 runtime, it raised error ImportError: cannot import name 'GenericMeta' from 'typing'

openapi-generator version
  • openapitools/openapi-generator-cli:v4.3.1
Steps to reproduce
Traceback (most recent call last):
  File "/***/python37_lab/test.py", line 3, in <module>
    import nomad_envoy_cli
  File "/***/.virtualenvs/py37/lib/python3.7/site-packages/nomad_envoy_cli/__init__.py", line 21, in <module>
    from nomad_envoy_cli.api.customs_api import CustomsApi
  File "/***/.virtualenvs/py37/lib/python3.7/site-packages/nomad_envoy_cli/api/__init__.py", line 6, in <module>
    from nomad_envoy_cli.api.customs_api import CustomsApi
  File "/***/.virtualenvs/py37/lib/python3.7/site-packages/nomad_envoy_cli/api/customs_api.py", line 21, in <module>
    from nomad_envoy_cli.api_client import ApiClient
  File "/***/.virtualenvs/py37/lib/python3.7/site-packages/nomad_envoy_cli/api_client.py", line 681, in <module>
    from .swagger_validator import SwaggerValidator
  File "/***/.virtualenvs/py37/lib/python3.7/site-packages/nomad_envoy_cli/swagger_validator.py", line 4, in <module>
    from typing import List, AnyStr, Any, Type, GenericMeta, Dict
ImportError: cannot import name 'GenericMeta' from 'typing' (/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/typing.py)
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/2022

Suggest a fix

error version:

import importlib
import json
from datetime import date, datetime
from typing import List, AnyStr, Any, Type, GenericMeta, Dict

class SwaggerValidator(object):

fixed:

import importlib
import json
from datetime import date, datetime
from typing import List, AnyStr, Any, Type, GenericMeta, Dict
try:
    from typing import GenericMeta  # python 3.6
except ImportError:
    # in 3.7, genericmeta doesn't exist but we don't need it
    class GenericMeta(type): pass

class SwaggerValidator(object):

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the generated Python client's swagger_validator.py, identified in the traceback, and reproduce the import under Python 3.7. Check the typing import and the reported compatibility behavior, then verify that importing the client succeeds on Python 3.7 and that the relevant generated-client tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.