Skip to content

Set type of keyword arguments to Dict[unicode, Any] in Python 2. #1971

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

Merged
merged 1 commit into from
Aug 1, 2016

Conversation

rowillia
Copy link
Contributor

@rowillia rowillia commented Aug 1, 2016

This fixes #1954

@@ -553,9 +553,14 @@ def is_implicit_any(t: Type) -> bool:
arg_type = self.named_generic_type('builtins.tuple',
[arg_type])
elif typ.arg_kinds[i] == nodes.ARG_STAR2:
if self.options.python_version[0] >= 3:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got an inkling there may be other places where the same thing is needed, we just haven't found them yet. If you put the logic in unicode_type() to return str_type() if version >= 3, then you can use just unicode_type() here and we can use it in future places too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@rowillia rowillia force-pushed the fix-mypy-issue-1954 branch from 5dcdfec to b0ed105 Compare August 1, 2016 16:43
@gvanrossum gvanrossum merged commit 51fa569 into python:master Aug 1, 2016
@gvanrossum
Copy link
Member

Sadly I am going to have to revert this. We have a bunch of code that is broken by it. Example:

from typing import Dict

def f(**kw):
    # type: (**int) -> None
    a = {}  # type: Dict[str, int]
    a = kw

The error is

__tmp__.py:6: error: Incompatible types in assignment (expression has type Dict[unicode, int], variable has type Dict[str, int])

(It's easy to construct other examples too, using kw[...] or kw.keys().)

gvanrossum pushed a commit that referenced this pull request Aug 2, 2016
…on 2. (#1971)"

This reverts commit 51fa569.

Sadly this breaks some of our code. :-(
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.

**kwargs should be of type Dict[Union[str, unicode], Any] in Python 2
2 participants