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

Fix warning about non-ascii warnings even when they are ascii #2810

Merged
merged 2 commits into from
Oct 3, 2017

Conversation

nicoddemus
Copy link
Member

Fix #2809

@@ -73,7 +73,7 @@ def catch_warnings_for_item(item):

if compat._PY2 and any(isinstance(m, compat.UNICODE_TYPES) for m in warn_msg.args):
new_args = [compat.safe_str(m) for m in warn_msg.args]
unicode_warning = warn_msg.args != new_args
unicode_warning = list(warn_msg.args) != new_args
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 was always issue the "unicode message non-ascii compatible" because warns_msg.args is a tuple, which always compares as different than a list.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.232% when pulling 94ae943 on nicoddemus:issue-2809 into 6690b8a on pytest-dev:master.

@RonnyPfannschmidt
Copy link
Member

interesting find ^^

@@ -72,8 +72,8 @@ def catch_warnings_for_item(item):
unicode_warning = False

if compat._PY2 and any(isinstance(m, compat.UNICODE_TYPES) for m in warn_msg.args):
new_args = [compat.safe_str(m) for m in warn_msg.args]
Copy link
Member Author

Choose a reason for hiding this comment

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

We didn't realize at the time, but this is incorrect, safe_str will return utf-8 encoded bytes, which is not ascii.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.232% when pulling e49db9c on nicoddemus:issue-2809 into 6690b8a on pytest-dev:master.

@@ -72,8 +72,8 @@ def catch_warnings_for_item(item):
unicode_warning = False

if compat._PY2 and any(isinstance(m, compat.UNICODE_TYPES) for m in warn_msg.args):
new_args = [compat.safe_str(m) for m in warn_msg.args]
unicode_warning = warn_msg.args != new_args
new_args = [m.encode('ascii', 'replace') for m in warn_msg.args]
Copy link
Member

Choose a reason for hiding this comment

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

i fear this one could count as a breaking change as output characters are removed now

Copy link
Member Author

Choose a reason for hiding this comment

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

You are absolutely right, thanks. Rebased.

@nicoddemus nicoddemus changed the base branch from master to features October 3, 2017 10:40
@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.5% when pulling fbb9e93 on nicoddemus:issue-2809 into d132c50 on pytest-dev:features.

@nicoddemus
Copy link
Member Author

Can we merge this @RonnyPfannschmidt ?

@RonnyPfannschmidt
Copy link
Member

@nicoddemus please add the changelog entry prefix for a deprecation/removal as this one is a bigger one

alltho i still don't see why we cant just escape

@nicoddemus
Copy link
Member Author

alltho i still don't see why we cant just escape

What do you mean? I'm open to suggestions here.

@RonnyPfannschmidt
Copy link
Member

@nicoddemus i dont see why we dont keep escaping as safe-string, why remove the unicode escapes

as far as i can tell it shouldnbt affect ascii, but it should affect non-ascii that way - just

i mean why not just use unicode-escape instead of safe_string for any unicode element?

@nicoddemus
Copy link
Member Author

i dont see why we dont keep escaping as safe-string, why remove the unicode escapes

Fair enough, I should have mentioned this: if we use safe_str, then we get another warning:

UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
    unicode_warning = list(warn_msg.args) != new_args

safe_str returns utf-8 encoded bytes. This warning was not appearing before because the comparison was short-circuiting because of the tuple != list comparison, which didn't even try to do element-wise comparison because the types were different.

Because of this, new_args cannot be converted to unicode using ascii, which is what Python tries to do with the right side of the comparison.

@nicoddemus
Copy link
Member Author

nicoddemus commented Oct 3, 2017

i mean why not just use unicode-escape instead of safe_string for any unicode element?

That's a good suggestion!

Used compat.ascii_escaped which does what you suggest.

Also renamed _ascii_escaped to ascii_escaped since it lives in the compat module which is internal anyway (all other functions in compat don't have a _ prefix as well).

@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.5% when pulling df6d5cd on nicoddemus:issue-2809 into d132c50 on pytest-dev:features.

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