Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python: Running function definitions with decorators ignores the decorator #77

Closed
radix opened this issue Jul 6, 2015 · 8 comments
Closed
Labels
language specific Not universal in all languages wontfix

Comments

@radix
Copy link
Contributor

radix commented Jul 6, 2015

Say we have this code:

def deco(f):
    return lambda x: f(x + 1)

@deco
def myfunc(x):
    return 1 / x

myfunc(0)

Trying to evaluate the myfunc function will be wrong in two different ways: if I have my cursor on the @deco line, it causes a syntax error because it seems to just be trying to evaluate @deco by itself, without the function definition after it. If I have my cursor on the def myfunc line, or on the blank line immediately after myfunc, it defines the function without the decorator.

I can work around this by manually selecting the whole function definition including the decorator line and then hitting cmd-alt-enter.

@willwhitney
Copy link
Collaborator

Hydrogen relies on Atom's code-folding and indentation right now to figure out what a block is. This is so that the code for finding blocks works across languages.

This is definitely annoying behavior, but I don't know of a way to address this without writing a parser for each language that Hydrogen supports. Which maybe we should do at some point, but isn't going to happen for a while.

Any ideas about how to solve this without breaking the problem out into all the languages?

@radix
Copy link
Contributor Author

radix commented Jul 7, 2015

sorry, I don't have any ideas. is it a bug in atom?

@willwhitney
Copy link
Collaborator

Nope, it's just hard to take a bunch of text and figure out what a logical block is cross-language. Atom is correct not to fold to decorators, as that would fold the actual function definition under.

@alvis
Copy link

alvis commented Aug 17, 2018

any suggestion to get around this problem?

@n-riesco
Copy link
Collaborator

@alvis A way around this is to use comments to define the execution cells in your code and use the command Hydrogen Run Cell and Move Down (Alt+Shift+Enter) to run them. E.g.:

image

@alvis
Copy link

alvis commented Aug 17, 2018

@n-riesco: Thanks for pointing out. It's smart to use the # In[]: syntax to separate cells. Never thought it'd be a way.

@mbroedl
Copy link

mbroedl commented Aug 19, 2018

Please have a look if the most recent commit in this PR nikitakit/hydrogen-python#10 work for you. I've just added exactly this functionality.

@kylebarron
Copy link
Contributor

This is as solved as possible through the use of cells and with hydrogen-python so I'm going to close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language specific Not universal in all languages wontfix
Projects
None yet
Development

No branches or pull requests

7 participants