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

enable filterwarnings=['error'] and strict-makers, strict-config #341

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
6 changes: 6 additions & 0 deletions cachecontrol/filewrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,9 @@ def _safe_read(self, amt: int) -> bytes:
self._close()

return data

def close(self):
Copy link
Member

Choose a reason for hiding this comment

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

Not sure I follow this: there's a _close method too, and it seems to be disjoint in implementation from this one. Does this have an effect on the rest of the changes in this PR?

Copy link
Contributor Author

@graingert graingert Nov 9, 2024

Choose a reason for hiding this comment

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

FileWrapper is assigned as a HTTPResponse._fp which if it has a close method gets called by HTTPResponse.close which if the request is streaming needs to be called by using the response as a context manager

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The windows issues are new and exciting, I'll have to investigate them later

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The _close is disjoint because it's called when the fp is exhausted and the buf has finished being written to, CallbackFileWrapper.close is called when the consumer of the response failed reading the body in some way, if the response was streaming

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does this have an effect on the rest of the changes in this PR?

It's needed otherwise you get a ResourceWarning that's propagated as an unraisable exception

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I resolved the windows issues - turns out there's a bug in cpython! I think I've found a cpython bug every time I've added filterwarnings=["error"] to a project!

graingert marked this conversation as resolved.
Show resolved Hide resolved
try:
self.__fp.close()
finally:
self.__buf.close()
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,6 @@ module = "msgpack"
ignore_missing_imports = true

[tool.pytest.ini_options]
addopts = "--strict-markers --strict-config"
norecursedirs = ["bin", "lib", "include", "build"]
filterwarnings = ["error"]
6 changes: 3 additions & 3 deletions tests/test_chunked_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_stream_is_cached(self, url, sess):
assert content_1 == content_2

def test_stream_is_not_cached_when_content_is_not_read(self, url, sess):
sess.get(url + "stream", stream=True)
resp = sess.get(url + "stream", stream=True)
with sess.get(url + "stream", stream=True) as r1:
with sess.get(url + "stream", stream=True) as resp:

assert not resp.from_cache
assert not resp.from_cache
Loading