Skip to content

Type alias fails but long version works. #10139

Closed
@shadycuz

Description

@shadycuz

Bug Report

mypy fails when an alias is used but not when the long form is used

To Reproduce

  1. import botostubs
    import botostubs
  2. Create type alias at top of file but but below the import
    # Type Alias
    Vpc = botostubs.EC2.Ec2Resource.Vpc
  3. assign alias to a functions return type
    def find_vpc(vpc_name: str) -> Vpc:
  4. Run mypy
    error: Variable "my_package.utils.aws.Vpc" is not valid as a type

Expected Behavior

I expected that I would be able to use the type alias. When I use the long form.

def find_vpc(vpc_name: str) -> botostubs.EC2.Ec2Resource.Vpc:

I do not get the error when I run mypy

Actual Behavior
It errors when using the alias.

Your Environment

  • Mypy version used:
mypy                0.800
mypy-extensions     0.4.3
  • Mypy command-line flags: I just pass the directory
  • Mypy configuration options from mypy.ini (and other config files):
[mypy]

[mypy-nox.*,pytest,docker.*,git.*,boto3.*,botostubs.*,botocore.*]
ignore_missing_imports = True
  • Python version used: 3.9
  • Operating system and version: Windows 10 WSL

Not sure if it means anything but my IDE (visual studio code with pylance) works with the alias:

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions