Skip to content

Python 3 support #7

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

Closed
wants to merge 3 commits into from
Closed

Python 3 support #7

wants to merge 3 commits into from

Conversation

dehnert
Copy link
Contributor

@dehnert dehnert commented Jan 16, 2017

It would be nice to have Python 3 support in python-zephyr. Here's a start, though I don't think it's complete (and I haven't gone to any effort to clean it up yet). (I'd have submitted this as an issue instead of a pull request, but issues appear disabled.)

One decision that probably deserves other opinions is whether the library should expose strings or bytes, and whether to accept bytes, strings, or both. My inclination is that the library should expose strings for ~everything, but I'm not sure how reasonable that is (and I don't have much experience with Python 3).

finally:
if newsubs:
free(newsubs);
pass
Copy link
Collaborator

Choose a reason for hiding this comment

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

what's the story with removing this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAICT subAll isn't used in PyZephyr itself anywhere, and based on the name I'm assuming that nothing in _zephyr is intended to be "public" (except for receive and ZNotice, of course, which are imported into zephyr's namespace). subAll didn't build (I think due to the byte/string mismatch), so I just removed it rather than trying to fix it. I could fix it instead.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we'll want to fix it; it's used by the Zulip/zephyr mirroring system.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good to know. Does it make sense to expose a bulk subscription interface through the Subscriptions class, then, so that API clients don't need to use _zephyr? (What's the motivation for using subAll rather than calling Subscriptions.add?)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep, it's to do a bulk subscribe. Important for perf when you're subscribing to thousands of classes.

@timabbott
Copy link
Collaborator

The first 2 commits look fine; I don't understand the third. @ebroder, @andersk can one of you also take a look?

@dehnert
Copy link
Contributor Author

dehnert commented Jan 17, 2017

Yeah, the first two are more solid. The third doesn't actually finish Python 3 compatibility, and depending on preferences for how to handle the byte/string boundary, it may not be particularly close to final form. Which gets back to the question of how we'd rather handle it. I think I'd prefer to interface with PyZephyr with strings and have it handle the conversions, but I'm not sure how reasonable that is. (I also think that might involve enough futzing with encodings to prefer to move some of the logic out of Cython and into actual Python...)

@@ -29,7 +35,6 @@ def __new__(cls):

def __del__(self):
_z.cancelSubs()
super(Subscriptions, self).__del__()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, I removed this based on the last answer from http://stackoverflow.com/questions/36722390/python-3-super-del, but judging by https://docs.python.org/3.3/reference/datamodel.html#object.__del__, it looks like we really are supposed to call it. (Not that not calling it has obviously broken yet.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this should stay; Python does not automatically call __del__ on the superclass.


if is_py3:
item = [bytes(i, "utf-8") for i in item]
print(item)
Copy link
Contributor

Choose a reason for hiding this comment

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

Debugging spew.

@@ -29,7 +35,6 @@ def __new__(cls):

def __del__(self):
_z.cancelSubs()
super(Subscriptions, self).__del__()
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this should stay; Python does not automatically call __del__ on the superclass.


if is_py3:
item = [bytes(i, "utf-8") for i in item]
Copy link
Contributor

Choose a reason for hiding this comment

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

This certainly shouldn’t be conditionally encoded; that makes the API different for different Python versions. The Python 3 version is wrong here, because you’re encoding not just the string passed to libzephyr, but also the string added to the Python set. One would expect that it would at least be possible (i.e. for a tuple that’s already in canonical format) for item in subscriptions to hold after subscriptions.add(item).

@dehnert
Copy link
Contributor Author

dehnert commented Jan 17, 2017

So, any thoughts on whether the API should be unicode or bytes? I figure I'll hold off on the cleanup until I have something that works, which is blocked on figuring out what the API should look like.

@dehnert
Copy link
Contributor Author

dehnert commented Oct 1, 2019

I don't know if there's any thinking about converting PyZephyr to Python 3? It's conceivable I could work on this again, but I'm still hoping for guidance on

One decision that probably deserves other opinions is whether the library should expose strings or bytes, and whether to accept bytes, strings, or both. My inclination is that the library should expose strings for ~everything, but I'm not sure how reasonable that is (and I don't have much experience with Python 3).

before I proceed.

@dehnert
Copy link
Contributor Author

dehnert commented Dec 9, 2019

Has anybody looked at Python 3 recently?

I think my inclination was:

  • zephyr should support strings everywhere, and possibly accept bytes too (even for Py2, returning unicode strings should be fine, right? and I don't know if it's reasonable to go straight from a version that's Py2-only to Py3-only, given the state of upstream Py2 support)
  • _zephyr should be private, with whatever API is easiest to make work in C
  • Anything that _zephyr has that clients commonly want (eg, subAll) should be exported to the zephyr module itself

scripts.mit.edu is working on an upgrade, for which we might care about Python 3. (Chiron would also certainly like Python 3.)

@timabbott
Copy link
Collaborator

timabbott commented Dec 9, 2019 via email

@quentinmit
Copy link
Contributor

Please see my PR #8 which adds complete Python 3 support without any API changes.

@dehnert dehnert closed this Dec 17, 2019
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.

4 participants