nbcommands icon indicating copy to clipboard operation
nbcommands copied to clipboard

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

Open ericmjl opened this issue 6 years ago • 6 comments
trafficstars

@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)

ericmjl avatar Nov 02 '19 20:11 ericmjl

@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. :smile:

ericmjl avatar Nov 04 '19 15:11 ericmjl

It's not a burden :sweat_smile: let me look into it today :+1:

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

vinayak-mehta avatar Nov 06 '19 07:11 vinayak-mehta

@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 avatar Nov 14 '19 22:11 vinayak-mehta

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

vinayak-mehta avatar Nov 15 '19 13:11 vinayak-mehta

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 avatar Nov 15 '19 13:11 vinayak-mehta

??func should work.

vinayak-mehta avatar Nov 15 '19 13:11 vinayak-mehta