79497739

Date: 2025-03-10 10:48:38
Score: 0.5
Natty:
Report link

I'd like to add to @DaniilFajnberg's answer: while the reason he stated are correct, there is a solution to the problem without actually # type: ignoreing all such cases (which could be numerous).

All you have to do is explicitly tell pylance type of the dictionary:

external_data: dict[str, typing.Any] = {
    'id': 123,
    'name': 'Vlad',
    'signup_ts': datetime.now(),
    'friends': [1, 2, 3],
}

user = User(**external_data)

This will make pylance very happy and the errors will go away :)

Reasons:
  • Has code block (-0.5):
  • User mentioned (1): @DaniilFajnberg's
Posted by: winwin