You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2015-05-21.09:16:55.969>labels= ['type-bug', '3.8', '3.9', '3.10', '3.11', 'library']
title='BZ2File objects do not have name attribute'updated_at=<Date2021-04-27.13:05:23.760>user='https://bugs.python.org/jojkosivek'
Unlike GzipFile the BZ2File does not have defined name attribute. The reading of this attribute results in: "AttributeError: 'BZ2File' object has no attribute 'name'".
I'd be happy to take a look at this one, if no one else is working on it.
jcd commented on Jun 2, 2015
jcdmannequin
Mannequin
More actions
I've got a fix for this now. In working on it, I've discovered that not all file-like objects have a .name attribute. io.BytesIO (which is used all over the test suite) does not. I've written a patch that always creates a .name attribute on BZ2File, but sets it to None if the associated file-like object has no .name.
See the linked branch
Reacted by Cristian Consonni
jcd commented on Jun 2, 2015
jcdmannequin
Mannequin
More actions
It's probably too late for this to get into 3.5, since we're already in betas. Pushing back to 3.6.
HasanDiwan commented on Apr 27, 2021
HasanDiwanmannequin
Mannequin
More actions
Patch adds a bz2.BZ2File.name property corresponding to the filename passed in.
I would expect BZ2File.name to be a string. Returning a PathLike means lots of legitimate string methods will not work on it. Also, it should be "name" as an attribute, not "name()" as a method, to match other existing interfaces.
Activity
jojkosivek commentedon May 21, 2015
Unlike GzipFile the BZ2File does not have defined name attribute. The reading of this attribute results in: "AttributeError: 'BZ2File' object has no attribute 'name'".
This is truly missing feature and wrong behaviour, compare:
https://hg.python.org/releasing/3.4.3/file/933c3041d548/Lib/gzip.py
and
https://hg.python.org/releasing/3.4.3/file/933c3041d548/Lib/bz2.py
In addition to that the BZ2File did have name attribute in python 2.7.* .
In attachment there is tar ball with example files, expected results in python 3 and results in python 2.
jcd commentedon May 26, 2015
I'd be happy to take a look at this one, if no one else is working on it.
jcd commentedon Jun 2, 2015
I've got a fix for this now. In working on it, I've discovered that not all file-like objects have a .name attribute. io.BytesIO (which is used all over the test suite) does not. I've written a patch that always creates a .name attribute on BZ2File, but sets it to None if the associated file-like object has no .name.
See the linked branch
jcd commentedon Jun 2, 2015
It's probably too late for this to get into 3.5, since we're already in betas. Pushing back to 3.6.
HasanDiwan commentedon Apr 27, 2021
Patch adds a bz2.BZ2File.name property corresponding to the filename passed in.
stestagg commentedon Apr 27, 2021
Please may you add a test that uses "io.BytesIO()" as the filename argument. BytesIO() objects do not have a 'name' attribute
roysmith commentedon Apr 27, 2021
The https://bitbucket.org/cliff/cpython#python24258 URL 404's
Looking at the attached bz2.py diff, I would change:
to special-case os.PathLike and do:
I would expect BZ2File.name to be a string. Returning a PathLike means lots of legitimate string methods will not work on it. Also, it should be "name" as an attribute, not "name()" as a method, to match other existing interfaces.
serhiy-storchaka commentedon Feb 26, 2024
It is the part of more complex issue #115961.