Thanks to visit codestin.com
Credit goes to github.com

Skip to content

I found Type Bug In Class10 **kwargs Function Example #7

@OsamaAiDev

Description

@OsamaAiDev

from typing import Dict

def greet(**xyz: Dict[str,str]) -> None:
print(xyz)

greet(a="pakistan", b='China')

here the bug is

Argument of type "Literal['pakistan']" cannot be assigned to parameter "a" of type "Dict[str, str]" in function "greet"
"Literal['pakistan']" is incompatible with "Dict[str, str]"

correct code is

def greet(**xyz: str) -> None:
print(xyz)

greet(a="pakistan", b='China')

here str indicates that each keyword argument should be a string. When calling greet, you can directly pass key-value pairs where both the keys and values are strings. The function will then receive them as a dictionary with string keys and string values. This should resolve the static type error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions