Auditory-Biophysics-Lab / Slicer-ABLTemporalBoneSegmentation

3D Slicer extension featuring spacing resampling, fiducial registration, and rigid registration of temporal bone images.
BSD 3-Clause "New" or "Revised" License
16 stars 2 forks source link

STYLE: Upgrade python syntax to 3.6 and newer #6

Closed jamesobutler closed 2 years ago

jamesobutler commented 2 years ago

Some syntax upgrading is necessary for Slicer-ABLTemporalBoneSegmentation as I noticed in https://slicer.cdash.org/viewBuildError.php?buildid=2625902 that there were syntax warnings. These warnings are present because Slicer recently upgrade from Python 3.6.7 to Python 3.9.10 in https://github.com/Slicer/Slicer/commit/34e48e8aef5dad19ec8a955d6f48a1940846e3f3.

The syntax warning in question started as of Python 3.8. https://docs.python.org/3.8/whatsnew/3.8.html#changes-in-python-behavior

The compiler now produces a SyntaxWarning when identity checks (is and is not) are used with certain types of literals (e.g. strings, numbers). These can often work by accident in CPython, but are not guaranteed by the language spec. The warning advises users to use equality tests (== and !=) instead. (Contributed by Serhiy Storchaka in bpo-34850.)

This PR uses pyupgrade to automatically upgrade python syntax to newer versions. The script listed below was run for Python 3.6+ syntax with changes committed, followed by Python 3.7+, then Python 3.8+ and finally Python 3.9+. There were no changes made when specifying Python 3.7+, 3.8+ or 3.9+ which is why there are no commits for those iterations.

Using pyupgrade

searchdirectory = "C:/Users/JamesButler/Documents/GitHub/Slicer-ABLTemporalBoneSegmentation" for root, , files in os.walk(search_directory): for file_item in files: file_path = os.path.join(root, file_item) if os.path.isfile(file_path) and file_path.endswith(".py"): subprocess.call(["PythonSlicer", "-m", "pyupgrade", "--py36-plus", file_path])

jamesobutler commented 2 years ago

@e-simpson or @ben-connors Can you help with the integration of this PR? Thanks!

ben-connors commented 2 years ago

Thanks!