Skip to content

[3.9] bpo-40701: tempfile mixes str and bytes in an inconsistent manner (GH-20442) #24734

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

Closed

Conversation

miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Mar 3, 2021

The case of tempfile.tempdir variable being bytes is now handled consistently.
The getters return the right type and no more error of mixing str and bytes unless explicitly caused by the user.

Adds a regression test.

Expands the documentation to clarify the behavior.

Co-authored-by: Eric L ewl+git@lavar.de
Co-authored-by: Gregory P. Smith greg@krypto.org
(cherry picked from commit 9c79274)

Co-authored-by: Eric L ericzolf@users.noreply.github.com

https://bugs.python.org/issue40701

…thonGH-20442)

The case of tempfile.tempdir variable being bytes is now handled consistently.
The getters return the right type and no more error of mixing str and bytes unless explicitly caused by the user.

Adds a regression test.

Expands the documentation to clarify the behavior.

Co-authored-by: Eric L <ewl+git@lavar.de>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
(cherry picked from commit 9c79274)

Co-authored-by: Eric L <ericzolf@users.noreply.github.com>
@gpshead
Copy link
Member

gpshead commented Mar 3, 2021

Assigning to @ambv as release manager to decide if this counts as a bugfix for 3.9 or not.

technically tempfile.gettempdir()'s API changes as it now always returns str. When in the past it blindly returned whatever tempfile.tempdir was set to when non-None. But that was mostly a bug as tempfile.tempdir being set to bytes didn't always work properly. and there is already a gettempdirb() function that explicitly returns bytes, implying that gettempdir() should be str.

@@ -248,6 +248,11 @@ The module defines the following user-callable items:
The result of this search is cached, see the description of
:data:`tempdir` below.

.. versionchanged:: 3.10
Copy link
Member

@gpshead gpshead Mar 3, 2021

Choose a reason for hiding this comment

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

if accepted in 3.9 as a bugfix, i'll update this to 3.9.5 or whatever is appropriate.

@gpshead
Copy link
Member

gpshead commented Mar 3, 2021

if you don't want this in 3.9, simply close the PR. :)

@miss-islington
Copy link
Contributor Author

@ericzolf and @gpshead: Status check is done, and it's a failure ❌ .

@github-actions
Copy link

github-actions bot commented Apr 3, 2021

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Apr 3, 2021
@gpshead gpshead requested a review from ambv April 4, 2021 03:31
@ericzolf
Copy link
Contributor

ericzolf commented Apr 8, 2021

Can I do something to help the process?

@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Apr 9, 2021
@gpshead
Copy link
Member

gpshead commented Apr 10, 2021

It is fixed in 3.10, the open question here is up to our 3.9 release manager @ambv to decide as to if this goes beyond a bug fix into behavior change territory.

explicit ``prefix``, ``suffix``, or ``dir`` arguments of type
str are supplied. Please do not write code expecting or
depending on this. This awkward behavior is maintained for
compatibility with the historcal implementation.
Copy link
Contributor

Choose a reason for hiding this comment

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

historical

@ambv
Copy link
Contributor

ambv commented Apr 10, 2021

Good change for 3.10, unclear if code in the wild isn't already using the wart of returning bytes from gettempdir(). Given that, it's cleaner to break compatibility with this API mistake on a new Python version.

@ambv ambv closed this Apr 10, 2021
@miss-islington miss-islington deleted the backport-9c79274-3.9 branch April 10, 2021 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review DO-NOT-MERGE type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants