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

Unable to use Unpack inside a Callable #16082

Closed
shadycuz opened this issue Sep 10, 2023 · 0 comments · Fixed by #16083
Closed

Unable to use Unpack inside a Callable #16082

shadycuz opened this issue Sep 10, 2023 · 0 comments · Fixed by #16083
Labels

Comments

@shadycuz
Copy link

Crash Report

I tried to use the Unpack inside of a callable.

Traceback

  File "mypy/semanal.py", line 808, in visit_func_def
  File "mypy/semanal.py", line 837, in analyze_func_def
  File "mypy/typeanal.py", line 865, in visit_callable_type
  File "mypy/typeanal.py", line 1391, in anal_array
  File "mypy/typeanal.py", line 1400, in anal_type
  File "mypy/types.py", line 1792, in accept
  File "mypy/typeanal.py", line 865, in visit_callable_type
  File "mypy/typeanal.py", line 1391, in anal_array
  File "mypy/typeanal.py", line 1400, in anal_type
  File "mypy/types.py", line 933, in accept
  File "mypy/typeanal.py", line 845, in visit_unpack_type
NotImplementedError


[6] Error running mypy in /workspaces/nvcloud: the mypy daemon crashed. This is probably a bug in mypy itself, see Output panel for details. The daemon will be restarted automatically.

To Reproduce

I tried to unpack a named tuple inside a callable.

class StackArgs(TypedDict):
    """The arguments that are passed to boto when creating or updating a stack.

    Args:
        StackName (str): The name of the stack to create, must be unique within the region.
        Capabilities (Sequence[CapabilityType]): A list of capabilities that the stack is granted.
        TemplateBody (Optional[str], optional): The Cloudformation template as a str. Defaults to None.
        TemplateURL (Optional[str], optional): A URL to the Cloudformation template. Defaults to None.
        Parameters (Optional[Sequence[ParameterTypeDef]], optional): The parameters to use when createing the stack.
        Defaults to None.
        Tags (Optional[Sequence[TagTypeDef]], optional): The tags to apply to the stack, which will get applied
        to all resources created by the stack. Defaults to None.
        EnableTerminationProtection (bool, optional): If enabled the stack is unable to be deleted until its removed.
        Defaults to False.
    """

    StackName: str
    TemplateBody: NotRequired[str]
    TemplateURL: NotRequired[str]
    Parameters: NotRequired[Sequence["ParameterTypeDef"]]
    DisableRollback: NotRequired[bool]
    RollbackConfiguration: NotRequired["RollbackConfigurationTypeDef"]
    TimeoutInMinutes: NotRequired[int]
    NotificationARNs: NotRequired[Sequence[str]]
    Capabilities: NotRequired[Sequence["CapabilityType"]]
    ResourceTypes: NotRequired[Sequence[str]]
    RoleARN: NotRequired[str]
    OnFailure: NotRequired["OnFailureType"]
    StackPolicyBody: NotRequired[str]
    StackPolicyURL: NotRequired[str]
    Tags: NotRequired[Sequence["TagTypeDef"]]
    ClientRequestToken: NotRequired[str]
    EnableTerminationProtection: NotRequired[bool]
    
class StackOperation(NamedTuple):
    name: str
    func: Callable[[Unpack[StackArgs]], "StackResource"]

Your Environment

  • Mypy version used: latest and 0.9X
  • Mypy command-line flags: None except path to file
  • Mypy configuration options from mypy.ini (and other config files): I have the experimental unpack feature turned on
  • Python version used: 3.10 and 11
  • Operating system and version: WSL

@ilevkivskyi

@shadycuz shadycuz added the crash label Sep 10, 2023
ilevkivskyi added a commit that referenced this issue Sep 11, 2023
Fixes #16082

Currently we only allow `Unpack` of a TypedDict when it appears in a
function definition. This PR also allows this in `Callable` types,
similarly to how we do this for variadic types.

Note this still doesn't allow having both variadic unpack and a
TypedDict unpack in the same `Callable`. Supporting this is tricky, so
let's not so this until people will actually ask for this. FWIW we can
always suggest callback protocols for such tricky cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant