Skip to content

typing: MultiDict.update accepts Iterable Mapping values. - #2142

Merged
pgjones merged 1 commit into
pallets:2.0.xfrom
MaicoTimmerman:multidict-update-typing
Jun 2, 2021
Merged

typing: MultiDict.update accepts Iterable Mapping values.#2142
pgjones merged 1 commit into
pallets:2.0.xfrom
MaicoTimmerman:multidict-update-typing

Conversation

@MaicoTimmerman

Copy link
Copy Markdown
Contributor

MultiDict.__init__ correctly represents it, however the update was missing the iterable variant.

Also, flipped the order of Iterable[V] and V fixes PyCharm's naive matching for generics. Mypy would accept both versions, however PyCharm would only try to infer Mapping's V as the List. By listing it second it will first try to map to the Iterable[V].

  • fixes #

Checklist:

  • Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • Add or update relevant docs, in the docs folder and in code.
  • Add an entry in CHANGES.rst summarizing the change and linking to the issue.
  • Add .. versionchanged:: entries in any relevant code docs.
  • Run pre-commit hooks and fix any issues.
  • Run pytest and tox, no tests failed.

@pgjones

pgjones commented Jun 1, 2021

Copy link
Copy Markdown
Member

Are you also able to report the ordering to PyCharm as a bug?

I've changed the target to 2.0.x.

@pgjones
pgjones changed the base branch from main to 2.0.x June 1, 2021 16:00
@pgjones

pgjones commented Jun 1, 2021

Copy link
Copy Markdown
Member

Could you add a changelog entry to note you've fixed the update method typing?

MultiDict.__init__ correctly represents it, however the update was
missing the iterable variant.

Also, flipped the order of Iterable[V] and V fixes PyCharm's naive
matching for generics. Mypy would accept both versions, however PyCharm
would only try to infer Mapping V as the List. By listing it second it
will first try to map to the Iterable[V].
@MaicoTimmerman
MaicoTimmerman force-pushed the multidict-update-typing branch from 4866501 to 736b811 Compare June 2, 2021 12:34
@MaicoTimmerman

Copy link
Copy Markdown
Contributor Author

@pgjones I've added a changelog entry.

I'll try and make time to create a minimal-reproducable example to submit to PyCharm.

@pgjones pgjones added the typing label Jun 2, 2021
@pgjones pgjones added this to the 2.0.2 milestone Jun 2, 2021
@pgjones
pgjones merged commit f61d9a3 into pallets:2.0.x Jun 2, 2021
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jun 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants