Skip to content

Replace relative imports from tutorial with absolute imports to avoid crashes #2048

@gustavonmartins

Description

@gustavonmartins

I had been following the official FastAPI tutorials and I have had many bugs. After some time understanding them and trying to fix, I saw they were due to the usage of relative imports.

Two person in my team had this problem independently and took some hours and tweaks to make a hack to this issue. In stackoverflow i also found many people having headches due to relative imports.

Only later I have found that PEP8 warns about pitfalls of relative imports and strongly advice for usage of absolute imports. After trying this, my code of the FastAPI tutorial worked.

Could you please use absolute imports in your tutorial to avoid this recurrent problem?
Thanks!

Source of recomendation of absolute imports over relative:
https://www.python.org/dev/peps/pep-0008/

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions