contrib/check-py3-compat.py
changeset 41555 ba7eaff26474
parent 41554 01417ca7f2e2
child 43076 2372284d9457
equal deleted inserted replaced
41554:01417ca7f2e2 41555:ba7eaff26474
    12 import ast
    12 import ast
    13 import importlib
    13 import importlib
    14 import os
    14 import os
    15 import sys
    15 import sys
    16 import traceback
    16 import traceback
       
    17 import warnings
    17 
    18 
    18 def check_compat_py2(f):
    19 def check_compat_py2(f):
    19     """Check Python 3 compatibility for a file with Python 2"""
    20     """Check Python 3 compatibility for a file with Python 2"""
    20     with open(f, 'rb') as fh:
    21     with open(f, 'rb') as fh:
    21         content = fh.read()
    22         content = fh.read()
    89         fn = check_compat_py2
    90         fn = check_compat_py2
    90     else:
    91     else:
    91         fn = check_compat_py3
    92         fn = check_compat_py3
    92 
    93 
    93     for f in sys.argv[1:]:
    94     for f in sys.argv[1:]:
    94         fn(f)
    95         with warnings.catch_warnings(record=True) as warns:
       
    96             fn(f)
       
    97 
       
    98         for w in warns:
       
    99             print(warnings.formatwarning(w.message, w.category,
       
   100                                          w.filename, w.lineno).rstrip())
    95 
   101 
    96     sys.exit(0)
   102     sys.exit(0)