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

Simplify away safe_text_dupfile/EncodedFile #6875

Closed
wants to merge 1 commit into from

Conversation

bluetech
Copy link
Member

@bluetech bluetech commented Mar 7, 2020

I tried to understand what the safe_text_dupfile() function and EncodedFile class do. Outside tests, EncodedFile is only used by safe_text_dupfile, and safe_text_dupfile is only used by FDCaptureBinary.__init__(). I then started to eliminate always-true conditions based on the single call site, and in the end nothing was left.

The old code had some workarounds:

I tried to understand what the `safe_text_dupfile()` function and
`EncodedFile` class do. Outside tests, `EncodedFile` is only used by
`safe_text_dupfile`, and `safe_text_dupfile` is only used by
`FDCaptureBinary.__init__()`. I then started to eliminate always-true
conditions based on the single call site, and in the end nothing was
left.

The old code had some workarounds:

- Ensure `errors` property is set: pytest-dev#555.
  It is set now, although now it will return `replace`, which is the
  actual method used also before, instead of `strict`. AFAIU, the issue
  just wanted it to be set to something, not `strict` specifically.

- Infinite recursion trying to pickle `EncodedFile` (f7282b8).
  Not sure, I don't think this object should be pickle-able at all (and
  it isn't...).

- A bug in `logging.Handler.__repr__` with int `file.name`.
  pytest-dev#2555
  Was fixed in Python>=3.7.4: https://bugs.python.org/issue36015.
  TODO: This workaround is probably still needed?
@@ -579,7 +526,7 @@ def _start(self):

def snap(self):
self.tmpfile.seek(0)
res = self.tmpfile.read()
res = self.tmpfile.buffer.read()
Copy link
Member Author

Choose a reason for hiding this comment

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

This I think is a bug fix anyway?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe fixes #6871 ?
Might make sense to pull it out then already.

Copy link
Contributor

@blueyed blueyed Mar 7, 2020

Choose a reason for hiding this comment

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

But would only avoid the indirection via __getattr__, no? (with EncodedFile being used)

@@ -621,10 +568,10 @@ class FDCapture(FDCaptureBinary):
EMPTY_BUFFER = str() # type: ignore

def snap(self):
res = super().snap()
Copy link
Member Author

Choose a reason for hiding this comment

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

Since tmpfile is now text-mode for reading also (not just for writing like the weird EncodedFile did), I switched to read directly. Also symmetric with the Sys variants which do the same.

@bluetech
Copy link
Member Author

bluetech commented Mar 7, 2020

Hmm, seems like TemporaryFiles(errors) was only added in py3.8. Will try to find a fix for that.

@bluetech
Copy link
Member Author

bluetech commented Mar 11, 2020

Replaced by #6899.

@bluetech bluetech closed this Mar 11, 2020
@bluetech bluetech deleted the rm-encodedfile branch July 14, 2020 07:18
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

2 participants