Skip to content

Change dict.fromkeys() test to be compatible with stricter type - #8474

Closed
bluetech wants to merge 1 commit into
python:masterfrom
bluetech:dict-fromkeys-test
Closed

bluetech wants to merge 1 commit into
python:masterfrom
bluetech:dict-fromkeys-test

Conversation

@bluetech

@bluetech bluetech commented Mar 2, 2020

Copy link
Copy Markdown
Contributor

dict.fromkeys([1,2]) has type Dict[int, Any]. The Any was probably intended and is exercised in this test. But this stands in the way of (maybe) making it stricter in typeshed, to be Dict[int, None].

Refs: python/typeshed#3799

`dict.fromkeys([1,2])` has type `Dict[int, Any]`. The `Any` was probably
intended and is exercised in this test. But this stands in the way of
(maybe) making it stricter in typeshed, to be `Dict[int, None]`.
@ilevkivskyi

Copy link
Copy Markdown
Member

TBH I don't really like this idea. I think it should be Dict[int, Optional[Any]] instead.

Even better until PEP 585 is implemented I think mypy could use partial types to infer value type from first assignment (like it does for empty lists, dicts, etc). But this is too much work for a rare case. So Optional[Any] seems like the best way forward to me.

@ilevkivskyi

Copy link
Copy Markdown
Member

Just to clarify, I think the existing test should pass.

@bluetech

bluetech commented Mar 7, 2020

Copy link
Copy Markdown
Contributor Author

OK, that's understandable.

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

Successfully merging this pull request may close these issues.

3 participants