Skip to content

Mypy complains about config attribute #900

Closed
@donkirkby

Description

@donkirkby

Describe the bug
Mypy generates this error on the env.py script:

Module has no attribute "config"; maybe "configure"?

Expected behavior
No error message on env.py script generated by the alembic init command.

To Reproduce

$ alembic init alembic
  Creating directory /project/alembic ...  done
  Creating directory /project/alembic/versions ...  done
  Generating /project/alembic.ini ...  done
  Generating /project/alembic/env.py ...  done
  Generating /project/alembic/script.py.mako ...  done
  Generating /project/alembic/README ...  done
  Please edit configuration/connection/logging settings in '/project/alembic.ini' before proceeding.
$ mypy .
alembic/env.py:10: error: Module has no attribute "config"; maybe "configure"?
Found 1 error in 1 file (checked 1 source file)
$ 

Error

alembic/env.py:10: error: Module has no attribute "config"; maybe "configure"?

Versions.

  • OS: Ubuntu 20.04
  • Python: 3.8.10
  • Alembic: 1.7.0 (also 1.7.1)
  • SQLAlchemy: 1.4.23
  • Database: None
  • DBAPI: ?
  • mypy: 0.910

Additional context
I worked around the problem by telling mypy not to check the config attribute on line 10 of env.py.

config = context.config  # type: ignore

It's just a guess, but I wondered if this type hint is confusing Mypy.

config: "Config" = None  # type:ignore[assignment]

Have a nice day!
Thanks for sharing the project, and thanks for adding type hints.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpep 484typing related issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions