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

Cleanup some old python 2 idioms #2640

Merged
merged 7 commits into from
Jun 29, 2020

Conversation

neutrinoceros
Copy link
Member

@neutrinoceros neutrinoceros commented Jun 13, 2020

  • Inheritance from object class is implicit in python 3 so there's no need to keep enforcing it after we dropped support for python 2.

The following were done semi-automatically through 2to3 + manual validation, since in many cases this tool will produce incorrect results (e.g. with sorting numpy arrays)

  • cleanup metaclass declarations
  • remove future imports
  • cleanup rare reliquary occurrences of long (-> int) and unicode (-> str)
  • ⚠️ two classes were implementing a next method instead of __next__, this change could break some downstream code if the deprecated syntax self.next() was used (should be a niche case and is easily fixed)
  • use builtin a = sorted(data) instead of a=list(data); a.sort() where relevant (i.e. where it doesn't cause performance hits by adding a copy step)
  • consistently use while True instead of while 1
  • cleanup type comparisons: use builtin isinstance(a, mytype) instead of type(a) is mytype. Within tests I conservatively assumed it's preferable to leave the more strict type comparison but replaced some == comparisons with is (I don't know if it's even possible to build case where they are not equivalent but the later is definetely correct).

@neutrinoceros neutrinoceros added enhancement Making something better code style Related to linting tools yt-4.0 feature targeted for the yt-4.0 release labels Jun 13, 2020
@neutrinoceros neutrinoceros marked this pull request as draft June 13, 2020 13:23
@neutrinoceros neutrinoceros changed the title cleanup class inheritance: stop inheriting from object Cleanup some old python 2 idioms Jun 13, 2020
@neutrinoceros neutrinoceros marked this pull request as ready for review June 13, 2020 14:30
Copy link
Member

@cphyc cphyc left a comment

Choose a reason for hiding this comment

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

Many files now start with a few empty lines, I left a couple suggestions.

Otherwise, this LGTM.

yt/data_objects/tests/test_octree.py Show resolved Hide resolved
yt/frontends/enzo/data_structures.py Outdated Show resolved Hide resolved
yt/frontends/enzo_p/data_structures.py Outdated Show resolved Hide resolved
yt/frontends/swift/tests/test_outputs.py Show resolved Hide resolved
yt/geometry/tests/fake_octree.py Outdated Show resolved Hide resolved
yt/utilities/grid_data_format/conversion/__init__.py Outdated Show resolved Hide resolved
yt/utilities/lib/cykdtree/tests/test_utils.py Outdated Show resolved Hide resolved
yt/utilities/sdf.py Outdated Show resolved Hide resolved
yt/visualization/volume_rendering/lens.py Outdated Show resolved Hide resolved
@neutrinoceros neutrinoceros force-pushed the cleanup_object_inheritance branch from ee0561e to ff843f0 Compare June 17, 2020 16:46
@neutrinoceros
Copy link
Member Author

Oops. I used [ci-skip] instead of [ci skip] and now the CI pipeline will be running for ever 🤦

@@ -1,4 +1,4 @@
from __future__ import print_function

Copy link
Member

Choose a reason for hiding this comment

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

@cphyc were you mentioning empty lines at the start of files because you'd like them to be removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch, fixing it right now

@@ -13,8 +13,7 @@ def test_cartesian_coordinates():
# We're going to load up a simple AMR grid and check its volume
# calculations and path length calculations.
ds = fake_amr_ds()
axes = list(set(ds.coordinates.axis_name.values()))
axes.sort()
axes = sorted(set(ds.coordinates.axis_name.values()))
Copy link
Member

Choose a reason for hiding this comment

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

👍 to this change

else:
a.sort(axis=axis)
sorted = a
a_sorted = a
Copy link
Member

Choose a reason for hiding this comment

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

I like this clearer variable name

@neutrinoceros neutrinoceros changed the base branch from yt-4.0 to master June 22, 2020 15:01
@neutrinoceros neutrinoceros force-pushed the cleanup_object_inheritance branch from 4f89ee8 to 592a21e Compare June 22, 2020 15:16
@neutrinoceros
Copy link
Member Author

@yt-fido test this please

@neutrinoceros
Copy link
Member Author

@yt-fido test this please

@munkm munkm merged commit 6befef2 into yt-project:master Jun 29, 2020
@neutrinoceros neutrinoceros deleted the cleanup_object_inheritance branch July 21, 2020 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code style Related to linting tools enhancement Making something better yt-4.0 feature targeted for the yt-4.0 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants