import ast def offset(source): function_def = ast.parse(source).body[0] decorator = function_def.decorator_list[0] return decorator.col_offset assert offset(""" @a() def b(): 0 """) == 0 assert offset(""" @a(x) def b(): 0 """) == 1 assert offset(""" @a def b(): 0 """) == 1