Skip to content

pandas-dev#28926 Mypy fix/extension json array #28989

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/tests/extension/json/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
class JSONDtype(ExtensionDtype):
type = abc.Mapping
name = "json"
na_value = UserDict()
Copy link
Member

Choose a reason for hiding this comment

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

@simonjayhawkins i know ive asked you this before, but why cant mypy figure this out on its own?

Copy link
Member

Choose a reason for hiding this comment

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

the revealed type for na_value is Revealed type is 'collections.UserDict[Any, Any]'.

mypy asks for more info to narrow the Any

na_value = UserDict() # type: UserDict
Copy link
Member

Choose a reason for hiding this comment

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

can you type this as Mapping[<type>, <type>]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So since this test is for JSONDtype we are looking at a Mapping[str, Any] correct? A custom JSON Type was/is discussed in python/typing#182

Copy link
Member

Choose a reason for hiding this comment

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

I think UserDict[str, Any] works

Copy link
Member

Choose a reason for hiding this comment

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

this will produce TypeError: 'ABCMeta' object is not subscriptable using python 3.6 syntax and will require a workaround, see https://mypy.readthedocs.io/en/latest/common_issues.html#using-classes-that-are-generic-in-stubs-but-not-at-runtime so probably best to use Mapping from typing.

Copy link
Member

Choose a reason for hiding this comment

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

I think UserDict[str, Any] works

This is OK. probably better than Mapping. just needs to be quoted for py3.6


@classmethod
def construct_array_type(cls):
Expand Down
3 changes: 0 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,6 @@ ignore_errors=True
[mypy-pandas.tests.extension.decimal.test_decimal]
ignore_errors=True

[mypy-pandas.tests.extension.json.array]
ignore_errors=True

[mypy-pandas.tests.extension.json.test_json]
ignore_errors=True

Expand Down