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

Tighten bytes/str boundaries and remove unnecessary coercing #547

Merged
merged 1 commit into from
Dec 17, 2020
Merged

Tighten bytes/str boundaries and remove unnecessary coercing #547

merged 1 commit into from
Dec 17, 2020

Conversation

jdufresne
Copy link
Contributor

Now that the project is Python 3 only, the boundaries between bytes and
Unicode strings is more explicit.

This allows removing several unnecessary force_bytes() and
force_unicode() calls that handled differences between Python 2 and
Python 3. All uses of force_unicode() have been removed.

For values that are known to be bytes, use .decode() instead. For
values are that known to be str, use .encode() instead. This strategy
makes the type explicit and reduces a function call.

Key handling continues to use force_bytes() to allow callers to pass
either bytes or str.

To help enforce bytes/str handling in the future, the -b option is
passed to Python when testing. This option will emit a warning if bytes
and str are improperly mixed together.

Now that the project is Python 3 only, the boundaries between bytes and
Unicode strings is more explicit.

This allows removing several unnecessary force_bytes() and
force_unicode() calls that handled differences between Python 2 and
Python 3. All uses of force_unicode() have been removed.

For values that are known to be bytes, use `.decode()` instead. For
values are that known to be str, use `.encode()` instead. This strategy
makes the type explicit and reduces a function call.

Key handling continues to use force_bytes() to allow callers to pass
either bytes or str.

To help enforce bytes/str handling in the future, the `-b` option is
passed to Python when testing. This option will emit a warning if bytes
and str are improperly mixed together.
@jpadilla jpadilla added this to the v2.0.0 milestone Dec 17, 2020
@jpadilla jpadilla merged commit 97cd403 into jpadilla:master Dec 17, 2020
@jdufresne jdufresne deleted the force-bytes branch December 18, 2020 00:49
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.

None yet

3 participants