comparison contrib/check-py3-compat.py @ 41554:01417ca7f2e2

check-py3-compat: provide filename to ast.parse() This ensures any warning/error messages print a valid filename instead of potentially '<unknown>'. Differential Revision: https://phab.mercurial-scm.org/D5844
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 04 Feb 2019 14:25:00 -0800
parents 778dc37ce683
children ba7eaff26474
comparison
equal deleted inserted replaced
41553:eb14ab7db33e 41554:01417ca7f2e2
43 """Check Python 3 compatibility of a file with Python 3.""" 43 """Check Python 3 compatibility of a file with Python 3."""
44 with open(f, 'rb') as fh: 44 with open(f, 'rb') as fh:
45 content = fh.read() 45 content = fh.read()
46 46
47 try: 47 try:
48 ast.parse(content) 48 ast.parse(content, filename=f)
49 except SyntaxError as e: 49 except SyntaxError as e:
50 print('%s: invalid syntax: %s' % (f, e)) 50 print('%s: invalid syntax: %s' % (f, e))
51 return 51 return
52 52
53 # Try to import the module. 53 # Try to import the module.