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

Define SettingCodes and improve ChangedSetting representation. #469

Merged
merged 1 commit into from
Feb 17, 2017

Conversation

Kriechi
Copy link
Member

@Kriechi Kriechi commented Feb 17, 2017

fixes #359
based on #303

@Kriechi Kriechi force-pushed the improve-repr branch 2 times, most recently from 66c0e9d to 6843036 Compare February 17, 2017 13:05
Copy link
Member

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

This is generally pretty good! I have a few small notes.

h2/settings.py Outdated
"""
All known HTTP/2 setting codes.

.. versionadded:: 2.5.3
Copy link
Member

Choose a reason for hiding this comment

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

This docstring can be dedented.

As to the versionadded comment, this won't be able to make it into the 2.5 release because this is a public part of the API, and so will need to go into 2.6. So the version added is 2.6.0.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

h2/settings.py Outdated
HEADER_TABLE_SIZE = SettingsFrame.HEADER_TABLE_SIZE
#:
#: .. deprecated:: 2.6.0
#: Deprecated in favour of :class:`SettingCodes.HEADER_TABLE_SIZE
Copy link
Member

Choose a reason for hiding this comment

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

These are all class but should be data, I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

MAX_FRAME_SIZE = SettingsFrame.MAX_FRAME_SIZE
def __init__(self, setting, original_value, new_value):
#: The setting code given. Either one of :class:`SettingCodes
#: <h2.settings.SettingCodes>` or ``int``
Copy link
Member

Choose a reason for hiding this comment

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

This should get a .. versionchanged:: 2.6.0 note as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

h2/settings.py Outdated
def __repr__(self):
return ("ChangedSetting(setting=%s, original_value=%s, "
"new_value=%s)") % (
self.setting.name,
Copy link
Member

Choose a reason for hiding this comment

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

Does .name work here in all cases?

Copy link
Member Author

Choose a reason for hiding this comment

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

It should... Do you want me to add an if isinstance(self.setting, SettingCodes) check?

Copy link
Member

Choose a reason for hiding this comment

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

Well, I mean: it definitely won't work for integers, right? 😁

Rather than isinstance, are you happy to just tolerate the default repr of an intenum member?

Copy link
Member Author

Choose a reason for hiding this comment

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

How about we make sure that the init of ChangedSetting always converts it to and SettingCodes object?

Copy link
Member

Choose a reason for hiding this comment

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

You can't convert to an enum if you don't have a member defined for that int.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I'll changed it to use the default repr.

h2/settings.py Outdated
"""
All known HTTP/2 setting codes.

.. versionadded:: 2.5.3
Copy link
Contributor

Choose a reason for hiding this comment

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

2.6.0, surely?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@Kriechi Kriechi force-pushed the improve-repr branch 4 times, most recently from 59be0d2 to d115923 Compare February 17, 2017 13:43
Copy link
Member

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Ok, one small note about list creation and then we're good to go I think.

h2/events.py Outdated
return "<RemoteSettingsChanged changed_settings:%s>" % (
self.changed_settings,
return "<RemoteSettingsChanged changed_settings:{%s}>" % (
", ".join([repr(cs) for cs in self.changed_settings.values()]),
Copy link
Member

Choose a reason for hiding this comment

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

Small note here, but you don't need the list. join works just fine on generators, so we can save ourselves the allocation of an intermediate list here and below.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

self.setting,
self.original_value,
self.new_value
)
Copy link
Member

Choose a reason for hiding this comment

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

Wow. This looks weird. It fits in with the code style, so...I guess we'll leave it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Either this, or you allow lines with more than 79 characters! 😄

Copy link
Member

Choose a reason for hiding this comment

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

NEVER!

Copy link
Member

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Cool, LGTM. Thanks for this @Kriechi! 🚀

self.setting,
self.original_value,
self.new_value
)
Copy link
Member

Choose a reason for hiding this comment

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

NEVER!

@Lukasa Lukasa merged commit a9b611a into python-hyper:master Feb 17, 2017
@Kriechi Kriechi deleted the improve-repr branch February 17, 2017 14:42
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.

Provide SettingsEnum to dynamically list and print
3 participants