swagger-api / swagger-api/swagger-codegen

[Python] AttributeError: module 'typing' has no attribute 'Type' in python 3.5.1

Open
#7,361 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

In python 3.5.1, type python -m swagger_server will get the following error:
File "/swagger-codegen/samples/server/petstore/flaskConnexion/swagger_server/models/base_model_.py", line 21, in Model
def from_dict(cls: typing.Type[T], dikt) -> T:
AttributeError: module 'typing' has no attribute 'Type'

Swagger-codegen version

2.3.0

Suggest a fix/enhancement
  1. edit swagger_server/models/base_model_.py
  2. add from typing import TypeVar, Generic after import typing
  3. replace the 22nd line as below

def from_dict(cls: typing.Type[T], dikt) -> T:
def from_dict(cls: typing.Generic[T], dikt) -> T:

  1. type python -m swagger_server to start the service and you would see:
    * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)

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 swagger_server/models/base_model_.py, especially the from_dict annotation around line 22, and reproduce the failure with python -m swagger_server under Python 3.5.1. Verify the compatibility change against the generated Flask service; done means the service starts and reports that it is running on port 8080.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
backend
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.