Bug 1330651

Summary: python-astrid doesn't ignore PyGIWarning warnings
Product: [Fedora] Fedora Reporter: Giuseppe Scrivano <gscrivan>
Component: python-astroidAssignee: Brian Lane <bcl>
Status: CLOSED RAWHIDE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rawhideCC: bcl, mrunge
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: python-astroid-1.4.5-2.fc25 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-04-27 21:47:40 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Giuseppe Scrivano 2016-04-26 16:26:30 UTC
Description of problem:

pylint doesn't ignore PyGIWarning warnings

Version-Release number of selected component (if applicable):

python-astroid 1.4.5-1.fc25

How reproducible:

100%

Steps to Reproduce:
Try pylint on the https://github.com/projectatomic/atomic.git source base

Actual results:

/usr/lib/python2.7/site-packages/astroid/brain/brain_gi.py:136: PyGIWarning: OSTree was imported without specifying a version first. Use gi.require_version('OSTree', '1.0') before import to ensure that the right version gets loaded.



Expected results:

not raising any warning

Additional info:

This patch fixed the problem for me:

--- /usr/lib/python2.7/site-packages/astroid/brain/brain_gi.py	2016-03-21 18:23:46.000000000 +0000
+++ /usr/lib/python2.7/site-packages/astroid/brain/brain_gi_new.py	2016-04-26 16:16:42.657432435 +0000
@@ -133,16 +133,17 @@
             modcode = ''
             for m in itertools.chain(modnames, optional_modnames):
                 try:
-                    __import__(m)
                     with warnings.catch_warnings():
                         # Just inspecting the code can raise gi deprecation
                         # warnings, so ignore them.
                         try:
-                            from gi import PyGIDeprecationWarning
+                            from gi import PyGIDeprecationWarning, PyGIWarning
                             warnings.simplefilter("ignore", PyGIDeprecationWarning)
+                            warnings.simplefilter("ignore", PyGIWarning)
                         except Exception:
                             pass
 
+                        __import__(m)
                         modcode += _gi_build_stub(sys.modules[m])
                 except ImportError:
                     if m not in optional_modnames:

Comment 1 Brian Lane 2016-04-26 23:17:18 UTC
Thanks! Could you also submit your patch upstream at: https://github.com/PyCQA/astroid

Comment 2 Giuseppe Scrivano 2016-04-27 13:14:39 UTC
pull request here:

https://github.com/PyCQA/astroid/pull/333