Skip to content

Conversation

@bdon
Copy link
Contributor

@bdon bdon commented Mar 21, 2017

Without type hints, 3 test failures on python2.7 (still investigating)

This PR is fixing module name clashes and using six to resolve differences in syntax and the standard library

bdon added 3 commits March 21, 2017 13:31
* import UserDict, range, urlparse from six.moves
* Configuration and HDXObject inherit from object for python 2.7
* check for unicode string type in addition to str
* add six to requirements.txt
* use six.raise_from(a,b) instead of raise a from b
* Check for either FileNotFoundError (python 3) or IOError (python 2.7).
* rename logging to hdx_logging and scraperwiki to hdx_scraperwiki
@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 95.663% when pulling e80e0c0 on bdon-python27 into b5c8f21 on master.


all_datasets = list()
dataset = Dataset()
total_rows = kwargs.get('rows', sys.maxsize)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Skeptical about this line, do you really want a generator going all the way up to sys.maxsize?

bdon added 2 commits March 21, 2017 13:47
* HDXObject and Configuration either UserDict.IterableUserDict (2.7) or collections.UserDict (3)
* on 2.7, call __setitem__ in initializer of IterableUserDict subclass
@coveralls
Copy link

Coverage Status

Coverage increased (+0.05%) to 95.693% when pulling 5fa0ea8 on bdon-python27 into b5c8f21 on master.

@bdon
Copy link
Contributor Author

bdon commented Mar 21, 2017

OK, all tests passing on python 2.7. The workaround is a bit hacky in smoothing over the difference between 3 collections.UserDict and 2.7 UserDict.UserDict, since the code iterates over the dict using for we need a 2.7 UserDict.IterableUserDict, which six doesn't handle.

Also 3's UserDict __init__ seems to call __setitem__ for each element in the initial_data parameter, but 2's IterableUserDict doesn't, so this needs to be done by hand, at least for the behavior in the class that depends on it (Dataset). But behavior outside of what's covered by the test suite may be different

super(Dataset,self).__init__({})
# workaround: python2 IterableUserDict does not call __setitem__ in __init__,
# while python3 collections.UserDict does
for d in initial_data:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a bit hacky, open to suggestions

@bdon bdon mentioned this pull request Mar 21, 2017
@mcarans
Copy link
Contributor

mcarans commented Mar 22, 2017

Thanks @bdon I will review. If I merge in your pull request and then @tim6her makes a pull request with type hints, is this likely to cause merge conflicts? I am not sure how well Git's merging will handle it. If you have suggestions about it, I'd be glad to hear them. If not or you don't know, I guess I'll find out by trying!

@tim6her
Copy link
Collaborator

tim6her commented Mar 22, 2017

Dear @mcarans , my studies are demanding all of my time this week so I won't finish the type hints before Friday. If you complete the review by then, I will just fetch @bdon 's changes and continue the reformatting from there.

@mcarans
Copy link
Contributor

mcarans commented Mar 22, 2017

@tim6her Great, I will endeavour to complete by then.

@mcarans
Copy link
Contributor

mcarans commented Mar 22, 2017

@bdon I see that the changes you have made allow the Python 3 tests to pass which is great. I am thinking that @tim6her should work off your branch before merging into master because it is not possible to test this PR under Python 2.7 with the Python 3 type hints still in there. Does this make sense?

@bdon
Copy link
Contributor Author

bdon commented Mar 22, 2017

Makes sense. If you do want to test it on Python 2.7 now, https://github.com/bdon/hdx-python-api/tree/bdon-python27 with HEAD at 1646e63 is the same, with another commit on top that has all type annotations removed.

@mcarans
Copy link
Contributor

mcarans commented Mar 22, 2017

@bdon Did you comment the type annotations by hand or is there a tool which does that?

It would be great if there was a tool that converted between Python 3 and Python 2.7 straddling code type annotations and back automatically :-)

@bdon
Copy link
Contributor Author

bdon commented Mar 22, 2017

Yes, I did it by hand. I don't have any tools to read the type annotations, so can't verify if any changes to them would be correct. Maybe PyCharm has a way to switch to the comment-based annotation mode?

@mcarans
Copy link
Contributor

mcarans commented Mar 22, 2017

I have made a request for PyCharm to add that feature but don't expect it any time soon
https://youtrack.jetbrains.com/issue/PY-23236

tim6her added a commit to tim6her/hdx-python-api that referenced this pull request Mar 24, 2017
@mcarans
Copy link
Contributor

mcarans commented Mar 24, 2017

"If you do want to test it on Python 2.7 now, https://github.com/bdon/hdx-python-api/tree/bdon-python27 with HEAD at 1646e63 is the same, with another commit on top that has all type annotations removed."

The tests there ran fine on 2.7 @tim6her

@mcarans mcarans merged commit 5fa0ea8 into master Mar 27, 2017
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.

5 participants