Skip to content

Mypy crashes when importing types_aiobotocore_s3 #16498

Closed

Description

@Apakottur

Crash report

Mypy 1.7.0 crashes when importing the most recent version of types_aiobotocore_s3 (2.7.0).

To reproduce:

I have the following file:

# test.py
import types_aiobotocore_s3

I'm getting a Mypy crash when running the following command:

mypy --show-traceback --disallow-any-unimported test.py

Getting same crash on mypy master branch.

Traceback

/opt/virtualenvs/cmd-N7MVwD3X-py3.11/lib/python3.11/site-packages/types_aiobotocore_s3/type_defs.pyi:565: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 1.7.0
Traceback (most recent call last):
  File "mypy/semanal.py", line 6525, in accept
  File "mypy/nodes.py", line 1308, in accept
  File "mypy/semanal.py", line 2855, in visit_assignment_stmt
  File "mypy/semanal.py", line 3152, in analyze_typeddict_assign
  File "mypy/semanal_typeddict.py", line 359, in check_typeddict
  File "mypy/semanal_typeddict.py", line 460, in parse_typeddict_args
  File "mypy/messages.py", line 1745, in unimported_type_becomes_any
  File "mypy/messages.py", line 2714, in format_type
  File "mypy/messages.py", line 2731, in format_type_bare
  File "mypy/messages.py", line 2486, in format_type_inner
  File "mypy/types.py", line 3074, in get_proper_type
TypeError: mypy.types.ProperType object expected; got mypy.types.RequiredType
/opt/virtualenvs/cmd-N7MVwD3X-py3.11/lib/python3.11/site-packages/types_aiobotocore_s3/type_defs.pyi:565: : note: use --pdb to drop into pdb

Your Environment

  • Mypy version used: 1.7.0
  • Mypy command-line flags: --show-traceback --disallow-any-unimported
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.11.6
  • Operating system and version: Docker image python:3.11.6-slim-bullseye

Activity

  1. AlexWaygood commented on Nov 15, 2023

    @AlexWaygood
    Member

    Hmm, I can't reproduce locally on py311 or py312

  2. miikka commented on Nov 15, 2023

    @miikka

    I'm running into same issue with Python 3.11.6 and mypy 1.4.1 in a real project, but I was able to reproduce the issue using the instructions above with Python 3.12.0 and mypy 1.7.0. Note that --disallow-any-unimported must be enabled; it works if it's disabled.

  3. JelleZijlstra commented on Nov 15, 2023

    @JelleZijlstra
    Member

    Reproduces for me in a clean venv.

    I reduced it to a single file:

    from typing import NotRequired, TypedDict
    from thismoduledoesntexist import TransferConfig
    
    B = TypedDict(
        "B",
        {
            "Config": NotRequired[TransferConfig],
        },
    )
    % mypy --show-traceback --disallow-any-unimported /tmp/type_defs.pyi
    /tmp/type_defs.pyi:2: error: Cannot find implementation or library stub for module named "thismoduledoesntexist"  [import-not-found]
    /tmp/type_defs.pyi:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
    /tmp/type_defs.pyi:4: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
    https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
    Please report a bug at https://github.com/python/mypy/issues
    version: 1.7.0
    Traceback (most recent call last):
      File "mypy/semanal.py", line 6525, in accept
      File "mypy/nodes.py", line 1308, in accept
      File "mypy/semanal.py", line 2855, in visit_assignment_stmt
      File "mypy/semanal.py", line 3152, in analyze_typeddict_assign
      File "mypy/semanal_typeddict.py", line 359, in check_typeddict
      File "mypy/semanal_typeddict.py", line 460, in parse_typeddict_args
      File "mypy/messages.py", line 1745, in unimported_type_becomes_any
      File "mypy/messages.py", line 2714, in format_type
      File "mypy/messages.py", line 2731, in format_type_bare
      File "mypy/messages.py", line 2486, in format_type_inner
      File "mypy/types.py", line 3074, in get_proper_type
    TypeError: mypy.types.ProperType object expected; got mypy.types.RequiredType
    /tmp/type_defs.pyi:4: : note: use --pdb to drop into pdb
    

    The problem seems to be a NotRequired containing an unimported type inside an old-stype TypedDict (class-style TypedDicts are fine).

  4. JelleZijlstra commented on Nov 15, 2023

    @JelleZijlstra
    Member

    Also reproduces as far back as mypy 1.4.1 (as @miikka wrote). I haven't tried to see how far back it reproduces, but it's not a recent regression.

  5. AlexWaygood commented on Nov 15, 2023

    @AlexWaygood
    Member

    Oh, I can reproduce with compiled mypy, but not uncompiled mypy (I was using uncompiled mypy). Because it's one of those runtime checks inserted by mypyc that's failing. Fun.

  6. AlexWaygood commented on Nov 15, 2023

    @AlexWaygood
    Member

    FWIW, here's how to get it to repro with uncompiled mypy: apply this diff to master:

    diff --git a/mypy/types.py b/mypy/types.py
    index e7738bd7d..3eabce15d 100644
    --- a/mypy/types.py
    +++ b/mypy/types.py
    @@ -3076,8 +3076,9 @@ def get_proper_type(typ: Type | None) -> ProperType | None:
             typ = typ.type_guard
         while isinstance(typ, TypeAliasType):
             typ = typ._expand_once()
    +    assert isinstance(typ, ProperType), type(typ)
         # TODO: store the name of original type alias on this type, so we can show it in errors.
    -    return cast(ProperType, typ)
    +    return typ
  7. changed the title [-]Mypy 1.7.0 crashes when importing `types_aiobotocore_s3`[/-] [+]Mypy crashes when importing `types_aiobotocore_s3`[/+] on Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions