python / python/typeshed

dict.update has incorrect variance for one of its overloads

Open
#3,551 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stubs: false positive
Dominant language
Python
Stars
5.1k
Forks
2.1k
Avg merge
1d 19h
Merged PRs (30d)
82

Description

from typing import Dict, Union

d: Dict[Union[str, int], None] = {}

e: Dict[str, None] = {}

# not ok
d.update(e)

# ok
d.update(e.items())

# ok
for key, value in e.items():
    d[key] = value

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the dict.update overloads in the Python stubs and reproduce the supplied example with a static type checker. Compare the rejected d.update(e) call with the accepted items() and assignment forms; done when the overload accepts the intended compatible mapping without weakening the other forms.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.