nbcommands
nbcommands copied to clipboard
Cannot parse ?? when specified at the end of function name
@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 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:
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.
@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.
@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?
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.
??func should work.