[Bug 1808133] Re: python3-apport emits a deprecation warning

Brian Murray brian at ubuntu.com
Wed Jan 9 16:16:06 UTC 2019


Bah, I forgot to reference this bug when fixing it.

apport (2.20.10-0ubuntu17) disco; urgency=medium

  * backends/packaging-apt-dpkg.py: switch to using python3-launchpadlib to
    communicate with Launchpad thereby gaining retry capabilities and using
    its cache.
  * backends/packaging-apt-dpkg.py: strip /usr from binary names so the .list
    file will match.
  * Re-enable Launchpad crash reports for disco.
  * test/*: switch from using deprecated imp to importlib, modify binary
    locations for merged-usr changes.
  * apport/report.py: reorder directories check for binaries so /usr is
    checked first.

** Changed in: apport (Ubuntu)
       Status: New => Fix Released

-- 
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:
  Fix Released

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