-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Use safe_str() to format warning message about unicode in Python 2 #4195
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Python 2: safely format warning message about passing unicode strings to ``warnings.warn``, which may cause | ||
surprising ``MemoryError`` exception when monkey patching ``warnings.warn`` itself. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,7 +123,7 @@ def warning_record_to_str(warning_message): | |
if unicode_warning: | ||
warnings.warn( | ||
"Warning is using unicode non convertible to ascii, " | ||
"converting to a safe representation:\n %s" % msg, | ||
"converting to a safe representation:\n {!r}".format(compat.safe_str(msg)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, when I suggested {!r}, then you don't need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh. Hmm well not sure if this will be a problem as is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No problem, just I was hoping to eventually remove safe_str usages 🤷♂️ |
||
UnicodeWarning, | ||
) | ||
return msg | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ envlist = | |
|
||
[testenv] | ||
commands = | ||
{env:_PYTEST_TOX_COVERAGE_RUN:} pytest --lsof | ||
{env:_PYTEST_TOX_COVERAGE_RUN:} pytest --lsof {posargs} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Zac-HD without posargs its impossible to run specific tests in calls like |
||
coverage: coverage combine | ||
coverage: coverage report | ||
passenv = USER USERNAME COVERAGE_* TRAVIS | ||
|
@@ -41,7 +41,7 @@ deps = | |
py27: mock | ||
nose | ||
commands = | ||
pytest -n auto --runpytest=subprocess | ||
pytest -n auto --runpytest=subprocess {posargs} | ||
|
||
|
||
[testenv:linting] | ||
|
@@ -58,7 +58,7 @@ deps = | |
hypothesis>=3.56 | ||
{env:_PYTEST_TOX_EXTRA_DEP:} | ||
commands = | ||
{env:_PYTEST_TOX_COVERAGE_RUN:} pytest -n auto | ||
{env:_PYTEST_TOX_COVERAGE_RUN:} pytest -n auto {posargs} | ||
|
||
[testenv:py36-xdist] | ||
# NOTE: copied from above due to https://github.com/tox-dev/tox/issues/706. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(comment for my own education about pytest's documentation)
In Hypothesis we have the
intersphinx_mapping
configured so that we can write these as:It allows for somewhat nicer formatting, but more importantly adds a hyperlink - and can check that the link target exists, which caught dozens of typos in our docs.
Has pytest decided not to do this, or just not considered it? It can be fiddly at times but also pretty useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't recall use taking a deeper look into this so it may be worth trying it - ideally someone with experience setting it up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll write up an issue then 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Zac-HD thanks a lot for the pointer, actually or
intersphinx_mapping
is already configured. I tested locally your changes and they actually do work. 😁We should remember to use those sphinx references more often. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm actually I spoke too soon. While it generates the proper docs, our linter complains: