[Bug 1808133] [NEW] python3-apport emits a deprecation warning

Serhiy Storchaka 1808133 at bugs.launchpad.net
Wed Dec 12 10:35:51 UTC 2018


Public bug reported:

python3-apport uses the deprecated module imp. This causes to emitting a
deprecation warning when run python3 with the -Walways option, and even
to changing a traceback when run python3 with the -Werror option.

Example:

```
$ python3 -Walways -c '1/0'
/usr/lib/python3/dist-packages/apport/report.py:13: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import fnmatch, glob, traceback, errno, sys, atexit, locale, imp
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ZeroDivisionError: division by zero
```
```
$ python3 -Werror -c '1/0'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ZeroDivisionError: division by zero
Error in sys.excepthook:                                                                                                                                                                                                                    
Traceback (most recent call last):                                                                                                                                                                                                          
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook                                                                                                                                                
    from apport.fileutils import likely_packaged, get_recent_crashes                                                                                                                                                                        
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>                                                                                                                                                             
    from apport.report import Report                                                                                                                                                                                                        
  File "/usr/lib/python3/dist-packages/apport/report.py", line 13, in <module>
    import fnmatch, glob, traceback, errno, sys, atexit, locale, imp
  File "/usr/lib/python3.6/imp.py", line 33, in <module>
    DeprecationWarning, stacklevel=2)
DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses

Original exception was:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ZeroDivisionError: division by zero
```

The -Werror option can be used for catching possible issues, and
additional output from apport spoils the result.

```
$ python3 -b -Werror -c 'str(b"")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
BytesWarning: str() on a bytes instance
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 13, in <module>
    import fnmatch, glob, traceback, errno, sys, atexit, locale, imp
  File "/usr/lib/python3.6/imp.py", line 33, in <module>
    DeprecationWarning, stacklevel=2)
DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses

Original exception was:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
BytesWarning: str() on a bytes instance
```

The solution is to silence DeprecationWarning for `import imp`:

import warnings
with warnings.catch_warnings():
    warnings.simplefilter('ignore', DeprecationWarning)
    import imp

** Affects: apport (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to apport in Ubuntu.
https://bugs.launchpad.net/bugs/1808133

Title:
  python3-apport emits a deprecation warning

Status in apport package in Ubuntu:
  New

Bug description:
  python3-apport uses the deprecated module imp. This causes to emitting
  a deprecation warning when run python3 with the -Walways option, and
  even to changing a traceback when run python3 with the -Werror option.

  Example:

  ```
  $ python3 -Walways -c '1/0'
  /usr/lib/python3/dist-packages/apport/report.py:13: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
    import fnmatch, glob, traceback, errno, sys, atexit, locale, imp
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
  ZeroDivisionError: division by zero
  ```
  ```
  $ python3 -Werror -c '1/0'
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
  ZeroDivisionError: division by zero
  Error in sys.excepthook:                                                                                                                                                                                                                    
  Traceback (most recent call last):                                                                                                                                                                                                          
    File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook                                                                                                                                                
      from apport.fileutils import likely_packaged, get_recent_crashes                                                                                                                                                                        
    File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>                                                                                                                                                             
      from apport.report import Report                                                                                                                                                                                                        
    File "/usr/lib/python3/dist-packages/apport/report.py", line 13, in <module>
      import fnmatch, glob, traceback, errno, sys, atexit, locale, imp
    File "/usr/lib/python3.6/imp.py", line 33, in <module>
      DeprecationWarning, stacklevel=2)
  DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses

  Original exception was:
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
  ZeroDivisionError: division by zero
  ```

  The -Werror option can be used for catching possible issues, and
  additional output from apport spoils the result.

  ```
  $ python3 -b -Werror -c 'str(b"")'
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
  BytesWarning: str() on a bytes instance
  Error in sys.excepthook:
  Traceback (most recent call last):
    File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
      from apport.fileutils import likely_packaged, get_recent_crashes
    File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
      from apport.report import Report
    File "/usr/lib/python3/dist-packages/apport/report.py", line 13, in <module>
      import fnmatch, glob, traceback, errno, sys, atexit, locale, imp
    File "/usr/lib/python3.6/imp.py", line 33, in <module>
      DeprecationWarning, stacklevel=2)
  DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses

  Original exception was:
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
  BytesWarning: str() on a bytes instance
  ```

  The solution is to silence DeprecationWarning for `import imp`:

  import warnings
  with warnings.catch_warnings():
      warnings.simplefilter('ignore', DeprecationWarning)
      import imp

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/apport/+bug/1808133/+subscriptions



More information about the foundations-bugs mailing list