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

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

Open
OsamaAiDev opened this issue Mar 31, 2024 · 0 comments
Open

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

OsamaAiDev opened this issue Mar 31, 2024 · 0 comments

Comments

@OsamaAiDev
Copy link

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.

@OsamaAiDev OsamaAiDev changed the title I found Type Bug In Class10 **kwargs I found Type Bug In Class10 **kwargs Function Example Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant