210 # This looks like a function call. |
210 # This looks like a function call. |
211 if t.type == token.NAME and _isop(i + 1, '('): |
211 if t.type == token.NAME and _isop(i + 1, '('): |
212 fn = t.string |
212 fn = t.string |
213 |
213 |
214 # *attr() builtins don't accept byte strings to 2nd argument. |
214 # *attr() builtins don't accept byte strings to 2nd argument. |
215 if ( |
215 if fn in ( |
216 fn |
216 'getattr', |
217 in ( |
217 'setattr', |
218 'getattr', |
218 'hasattr', |
219 'setattr', |
219 'safehasattr', |
220 'hasattr', |
220 'wrapfunction', |
221 'safehasattr', |
221 'wrapclass', |
222 'wrapfunction', |
222 'addattr', |
223 'wrapclass', |
|
224 'addattr', |
|
225 ) |
|
226 and (opts['allow-attr-methods'] or not _isop(i - 1, '.')) |
|
227 ): |
223 ): |
228 arg1idx = _findargnofcall(1) |
224 arg1idx = _findargnofcall(1) |
229 if arg1idx is not None: |
225 if arg1idx is not None: |
230 _ensuresysstr(arg1idx) |
226 _ensuresysstr(arg1idx) |
231 |
227 |
310 action='store_true', |
306 action='store_true', |
311 default=False, |
307 default=False, |
312 help='rewrite iteritems() and itervalues()', |
308 help='rewrite iteritems() and itervalues()', |
313 ), |
309 ), |
314 ap.add_argument( |
310 ap.add_argument( |
315 '--allow-attr-methods', |
|
316 action='store_true', |
|
317 default=False, |
|
318 help='also handle attr*() when they are methods', |
|
319 ), |
|
320 ap.add_argument( |
|
321 '--treat-as-kwargs', |
311 '--treat-as-kwargs', |
322 nargs="+", |
312 nargs="+", |
323 default=[], |
313 default=[], |
324 help="ignore kwargs-like objects", |
314 help="ignore kwargs-like objects", |
325 ), |
315 ), |
326 ap.add_argument('files', metavar='FILE', nargs='+', help='source file') |
316 ap.add_argument('files', metavar='FILE', nargs='+', help='source file') |
327 args = ap.parse_args() |
317 args = ap.parse_args() |
328 opts = { |
318 opts = { |
329 'dictiter': args.dictiter, |
319 'dictiter': args.dictiter, |
330 'treat-as-kwargs': set(args.treat_as_kwargs), |
320 'treat-as-kwargs': set(args.treat_as_kwargs), |
331 'allow-attr-methods': args.allow_attr_methods, |
|
332 } |
321 } |
333 for fname in args.files: |
322 for fname in args.files: |
334 fname = os.path.realpath(fname) |
323 fname = os.path.realpath(fname) |
335 if args.inplace: |
324 if args.inplace: |
336 with editinplace(fname) as fout: |
325 with editinplace(fname) as fout: |