Skip to content
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

Python3 builtin changes #1770

Merged
merged 14 commits into from
Sep 9, 2015
Merged

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Sep 7, 2015

Several builtins have changed names or semantics and require a bit of special handling.

  • x.next() -> next(x)
  • div -> truediv, __and__ -> and_
  • nested contexts
  • namedtuple.__init__ -> namedtuple.__new__
  • Rename of builtin package
  • Formatting of floats (see Test Python3 on travis-ci cartopy#426)
  • mock -> unittest.mock

try:
op = operator.itruediv if in_place else operator.truediv
except AttributeError:
op = operator.idiv if in_place else operator.div
return _binary_op_common(op, 'divison', cube, other, new_unit, dim,
Copy link
Member Author

Choose a reason for hiding this comment

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

Just noticed there's a typo here; I don't know what that second parameter is used for though.

Copy link
Member

Choose a reason for hiding this comment

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

What's the typo? 😕

Copy link
Member

Choose a reason for hiding this comment

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

divison -> division

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @ajdawson 😄

Copy link
Member

Choose a reason for hiding this comment

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

I don't know what that second parameter is used for though.

It's used to customise various errors messages in _assert_matching_units and _broadcast_cube_coord_data. From the error that begins "Could not determine dimension..." it looks like the best value for this string would be the name of the function, i.e. "divide".

Copy link
Member

Choose a reason for hiding this comment

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

divison -> division

I suggest I fix that in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

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

See #1775.

@QuLogic QuLogic mentioned this pull request Sep 7, 2015
14 tasks
try:
op = operator.itruediv if in_place else operator.truediv
except AttributeError:
op = operator.idiv if in_place else operator.div
Copy link
Member

Choose a reason for hiding this comment

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

  1. I don't see why an AttributeError would ever get raised - Python 2 and 3 both define operator.[i]truediv.
  2. Changing from [i]div to [i]truediv is a change of behaviour for Python 2.

Copy link
Member

Choose a reason for hiding this comment

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

NB. (1) also applies to the other changes in this commit.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea, I think you're right; I probably swapped them accidentally, because Python 3 definitely doesn't have [i]div.

@QuLogic
Copy link
Member Author

QuLogic commented Sep 8, 2015

WRT the floats, this is the method we ended up using in Cartopy. Using repr does seem to work for what I've tried so far as well, but you should also check on 32-bit.

Also, add aliases on custom classes for __next__ vs. next.
The correct constructor for a namedtuple is __new__, not __init__.
The __builtin__ module was renamed to builtins.
It is called assertCountEqual in Python 3.
The number of digits in the str-ified version differs between Python
versions.
On Python 2, the underlying file is in the file attribute. On Python 3,
the actual object acts exactly like a file.
The number of digits in the str-ified version differs between Python
versions. This change is the same as used in GeogCS.
@QuLogic QuLogic force-pushed the py3k-builtin-changes branch from e6ac88c to b136de8 Compare September 9, 2015 08:20
rhattersley added a commit that referenced this pull request Sep 9, 2015
@rhattersley rhattersley merged commit 0a27959 into SciTools:master Sep 9, 2015
@rhattersley
Copy link
Member

This PR represents a big chunk of work - thanks @QuLogic! 😄

@QuLogic QuLogic deleted the py3k-builtin-changes branch September 9, 2015 21:23
@QuLogic QuLogic modified the milestone: v1.9 Sep 12, 2015
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