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

Cannot parse ?? when specified at the end of function name #11

Open
ericmjl opened this issue Nov 2, 2019 · 6 comments · Fixed by #17
Open

Cannot parse ?? when specified at the end of function name #11

ericmjl opened this issue Nov 2, 2019 · 6 comments · Fixed by #17
Labels
bug Something isn't working

Comments

@ericmjl
Copy link
Contributor

ericmjl commented Nov 2, 2019

@vinayak-mehta thanks for handling #9 so quickly! I just upgraded nbcommands, and I think I might have found one more edge case, I hope you don't mind me reporting this here.

There are some code cells where we want to show the source of the function, so we write:

func_name??

to show the full source, or

func_name?

to show just the signature + docstring (if I remember correctly).

This example, I think, also gave me an error, this time being:

black.InvalidInput: Cannot parse: 1:6: func_name??

I dug into the source, and saw that you basically added a regex replacement, is that right? Would the correct thing to do here be the following? I think the order has to be the double-?? before the single-?.

source = re.sub("^??", "#??", source, flags=re.M)
source = re.sub("^?", "#?", source, flags=re.M)

# followed by...

black_source = re.sub("^#??", "??", black_source, flags=re.M)
black_source = re.sub("^#?", "?", black_source, flags=re.M)
@vinayak-mehta vinayak-mehta added the bug Something isn't working label Nov 3, 2019
@ericmjl
Copy link
Contributor Author

ericmjl commented Nov 4, 2019

@vinayak-mehta please let me know if you think I'm on the right track. If so, I'm happy to make a PR to help lessen your burden. 😄

@vinayak-mehta
Copy link
Owner

vinayak-mehta commented Nov 6, 2019

It's not a burden 😅 let me look into it today 👍

EDIT: I was not able to check this out, but this is on my backlog.

@vinayak-mehta
Copy link
Owner

@ericmjl I wasn't able to check this out, would you like to raise a PR for this? I've never used the ?? syntax so wasn't aware of this edge case.

@vinayak-mehta
Copy link
Owner

@ericmjl Looks like the change in the PR didn't work as expected. Fixed it in 1f0bf1c. Can you test and see if it works for you?

@vinayak-mehta
Copy link
Owner

Also re-opening the issue since nbblack will throw an error if ?? is specified at the end of the function name, and not the start.

@vinayak-mehta vinayak-mehta reopened this Nov 15, 2019
@vinayak-mehta
Copy link
Owner

??func should work.

@vinayak-mehta vinayak-mehta changed the title Cannot parse "??" and "?" when trying to show source from a code cell Cannot parse ?? when specified at the end of function name Nov 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants