Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overload stubs missing for get_x_argument #1146

Closed
vfazio opened this issue Dec 29, 2022 · 1 comment
Closed

overload stubs missing for get_x_argument #1146

vfazio opened this issue Dec 29, 2022 · 1 comment
Labels
bug Something isn't working pep 484 typing related issues

Comments

@vfazio
Copy link
Contributor

vfazio commented Dec 29, 2022

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!

@vfazio vfazio added the requires triage New issue that requires categorization label Dec 29, 2022
vfazio added a commit to vfazio/alembic that referenced this issue Dec 29, 2022
Fixes: sqlalchemy#1146

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
@CaselIT CaselIT added bug Something isn't working pep 484 typing related issues and removed requires triage New issue that requires categorization labels Dec 30, 2022
@CaselIT
Copy link
Member

CaselIT commented Dec 30, 2022

Thanks for reporting

vfazio added a commit to vfazio/alembic that referenced this issue Dec 30, 2022
Fixes: sqlalchemy#1146

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
vfazio added a commit to vfazio/alembic that referenced this issue Dec 30, 2022
Fixes: sqlalchemy#1146

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
vfazio added a commit to vfazio/alembic that referenced this issue Dec 30, 2022
Fixes: sqlalchemy#1146

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pep 484 typing related issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants