-
Notifications
You must be signed in to change notification settings - Fork 283
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
Python3 builtin changes #1770
Conversation
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, |
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.
Just noticed there's a typo here; I don't know what that second parameter is used for though.
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.
What's the typo? 😕
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.
divison -> division
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.
Thanks @ajdawson 😄
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 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".
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.
divison -> division
I suggest I fix that in a separate PR.
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.
See #1775.
try: | ||
op = operator.itruediv if in_place else operator.truediv | ||
except AttributeError: | ||
op = operator.idiv if in_place else operator.div |
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 see why an AttributeError would ever get raised - Python 2 and 3 both define
operator.[i]truediv
. - Changing from
[i]div
to[i]truediv
is a change of behaviour for Python 2.
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.
NB. (1) also applies to the other changes in this commit.
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.
Yea, I think you're right; I probably swapped them accidentally, because Python 3 definitely doesn't have [i]div
.
WRT the floats, this is the method we ended up using in Cartopy. Using |
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.
e6ac88c
to
b136de8
Compare
This PR represents a big chunk of work - thanks @QuLogic! 😄 |
Several builtins have changed names or semantics and require a bit of special handling.
x.next()
->next(x)
div
->truediv
,__and__
->and_
namedtuple.__init__
->namedtuple.__new__
mock
->unittest.mock