Skip to content

overload stubs missing for get_x_argument #1146

@vfazio

Description

@vfazio

Describe the bug

The context.pyi does not have stubs for the function overloads specified in environment.py

    @overload
    def get_x_argument(  # type:ignore[misc]
        self, as_dictionary: Literal[False] = ...
    ) -> List[str]:
        ...

    @overload
    def get_x_argument(  # type:ignore[misc]
        self, as_dictionary: Literal[True] = ...
    ) -> Dict[str, str]:
        ...

    def get_x_argument(
        self, as_dictionary: bool = False
    ) -> Union[List[str], Dict[str, str]]:

This will cause typing errors if trying to use:

cmd_line_path = context.get_x_argument(as_dictionary=True).get("dbpath", None)
migrations/env.py:71:21: error: Item "List[str]" of "Union[List[str], Dict[str, str]]" has no attribute "get"  [union-attr]

Since the default typing for the function allows it to return List[str] even though specifying as_dictionary should narrow the return type.

Expected behavior

There should be no typing error once @overload stubs are added

To Reproduce
Please try to provide a Minimal, Complete, and Verifiable example, with the migration script and/or the SQLAlchemy tables or models involved.
See also Reporting Bugs on the website.

# Insert code here

Error

# Copy error here. Please include the full stack trace.

Versions.

  • OS:
  • Python:
  • Alembic:
  • SQLAlchemy:
  • Database:
  • DBAPI:

Additional context

Have a nice day!

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