Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
@compile looks for function body via ':' lookup without regard to type hints #3317
Trying to use @compile on an annotated function in python 3.8.1:
@compile def func(z: c.int): pass
Is it possible to add a
Or perhaps better, can we set the default language level to 3 at this time?
(Ignore my previous, now deleted comment, about how it works for me - I forgot that the functions are only compiled when you actually use them)
Thanks! Sorry for the double, edited the title
That's almost crudely accurate - if it's not a lambda, it starts after the first
def get_body(source): ''' Crude attempt at getting the function body ''' # first_newline = source.index('\n') body = '' ix = -1 while not body: ix = source.index(':', ix+1) # Does this work? I think the indices should be - # if source[ix-5:ix] == 'lambda': if source[:5] == 'lambda': body = "return %s" % source[ix+1:] elif source[ix+1] in ('\r', '\n'): body = source[ix+2:] else: continue return body
For a function containing a single statement there's no need for a newline...
Lambda's can have colons....
It actually look pretty hard to get right - I'd guess that it'd be best taken from Cython's parser, because anything else would need to replicate a good chunk of the parser to cover all the corner cases. I realise I'm being more unhelpful than helpful here.