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

chore: drop Python 2 syntax #526

Merged
merged 2 commits into from
Dec 10, 2021
Merged

Conversation

henryiii
Copy link
Member

First commit is mostly automated, second commend is hand cleanup for things the first one didn't catch. Many .format's are left, this is just the easy ones that clearly are simpler as f-strings. Manual comparisons with sys.version_info are always preferred, and can be automatically cleaned up, so I had to look around for the try/catch ones. I'll note some cleanups inline.

src/uproot/_util.py Outdated Show resolved Hide resolved
src/uproot/_util.py Outdated Show resolved Hide resolved
src/uproot/extras.py Outdated Show resolved Hide resolved
@henryiii henryiii marked this pull request as draft December 10, 2021 16:46
@jpivarski
Copy link
Member

These are great, but please don't do this on the Awkward codebase yet: I'm in the middle of a "change everything" PR (scikit-hep/awkward#1184) that wouldn't merge well with this sort of thing.

@henryiii
Copy link
Member Author

Okay, no problem. Will stick with this. :) I'm going to do a couple more changes (I should be able to detect and replace {repr(x)} with {x!r}).

I think the main question: do you want to chain or hide the ModuleNotFoundErrors in extras?

@henryiii
Copy link
Member Author

I've also got a few more changes I want to annotate above, so I put it into draft

Comment on lines -13 to +12
uproot._util.py36,
sys.version_info < (3, 7),
Copy link
Member Author

Choose a reason for hiding this comment

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

I dropped this one helper; the sys.version_info is much easier to handle statically (pyupgrade can remove branches when it uses this syntax, for example), reads better (you don't have to look up the meaning of py36), and was the only place this helper was used.

Copy link
Member

Choose a reason for hiding this comment

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

There was a pack of py26, py27, py35, py36 booleans, as well as an iswin. The py36 was only needed in one case, which is why I still consider Python 3.6 acceptable—it needs very few work-arounds.

Meanwhile, there are a lot of different ways of saying sys.version_info[0] == 3 and sys.version_info[1] < 7, etc. (which mean subtly different things). This tuple-inequality idiom is succinct, and if it's recognized by static checkers, then it's the one to use. But I didn't know that there was a "one to use."

Similarly for the Windows-check: iswin has been redefined a few times as some ways of checking platform haven't been as robust as the one we have there now. By putting it in a boolean, we could fix it centrally.

Another one is isstr, which was a lot more important when we had to deal with different meanings of str, bytes, and unicode.

The isint is one that I think should stay. There isn't a good idiom for "integer but not boolean." There was some version of NumPy where NumPy scalars weren't being recognized as integers (can't remember which, exactly) and anyway Python and NumPy differ on whether booleans should be considered integers. Having a central facility for that makes it possible to control from one location.

return lzma
else:
return lzma
return lzma
Copy link
Member Author

Choose a reason for hiding this comment

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

This function is kind of pointless now, don't know if you want to deprecate it.

Copy link
Member

Choose a reason for hiding this comment

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

I had that in the back of my mind: we don't have to get lzma from extras.py anymore; it can be a top-of-the-module import. I think it only appears in compression.py.

@henryiii henryiii marked this pull request as ready for review December 10, 2021 17:26
@henryiii
Copy link
Member Author

Okay, I think I'm done with this. Some things (like + -> strings) could be worked on in the future, but don't need to be here.

@jpivarski
Copy link
Member

I scanned through all the changes and it looks good! With so many changes, the real proof that it's safe is in the tests. After it's merged, the Coffea tests should pick it up (is that right, @nsmith-?) and as a squashed commit, we have the option to revert it if there's a problem.

Thank you very much! (Also for that note about when tobytes was added to NumPy. We're still testing from 1.13.1 onward.)

@jpivarski jpivarski merged commit 2240779 into scikit-hep:main Dec 10, 2021
@henryiii henryiii deleted the henryiii/chore/py3 branch December 10, 2021 17:50
@nsmith-
Copy link
Member

nsmith- commented Dec 10, 2021

Yes coffea requires awkward>=1.5.1,<2 and the daily tests will end up picking the latest version once its on pypi

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