-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
pandas-dev#28926 Mypy fix/extension json array #28989
pandas-dev#28926 Mypy fix/extension json array #28989
Conversation
@@ -27,7 +27,7 @@ | |||
class JSONDtype(ExtensionDtype): | |||
type = abc.Mapping | |||
name = "json" | |||
na_value = UserDict() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aaditya-panik Thanks for the PR.
pandas/tests/extension/json/array.py
Outdated
@@ -27,7 +27,7 @@ | |||
class JSONDtype(ExtensionDtype): | |||
type = abc.Mapping | |||
name = "json" | |||
na_value = UserDict() | |||
na_value = UserDict() # type: UserDict |
There was a problem hiding this comment.
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>]
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you merge master, address comment and see if we can get CI green?
@@ -27,7 +28,7 @@ | |||
class JSONDtype(ExtensionDtype): | |||
type = abc.Mapping | |||
name = "json" | |||
na_value = UserDict() | |||
na_value = UserDict() # type: Mapping[type, type] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think type
should be used for subscripts; I think just Mapping[str, Any]
is fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will need to change to py3.6 syntax.
@aaditya-panik are you still working on this? Looks like there are a final few comments to address |
Looks like this has gone stale so closing for now but ping if you'd like to pick back up and address comments |
ref: #28926
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff