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

feat: allow python prefixed strings (f,b,r,u) with single quotes #377

Closed
wants to merge 3 commits into from

Conversation

ribru17
Copy link
Contributor

@ribru17 ribru17 commented Jul 29, 2023

Fixes #376

Allows autopairing of single quotes after f, b, r, u (and the capital variants).

@DenZhigalov
Copy link

Hi! I am just a random user. Just to let you know, I tried your version and behavior is still inconsistent for me.
input f"{ -> f"{}"
input f'{ -> f'{'}
If you don't mind please try that and tell me if that is something that still needs to be fixed or maybe that's just a problem with my config.

@ribru17
Copy link
Contributor Author

ribru17 commented Jul 30, 2023

Ahh, thanks for pointing this out :/ The issue I have found is that the check is_in_quotes fails (line 72) because there is a check that this will return false for single quotes following a word (to prevent it from thinking an apostrophe means it is inside a quote). I found a solution but I don't think it is a good one, it just hardcodes this part to pass when in Python. I think I will wait and see what @windwp thinks

@windwp
Copy link
Owner

windwp commented Aug 1, 2023

Can you add testcase.

I agree with you about modify function isinquote for python is not good.

You should create it from scratch with Rule.
or you can use a second parameter on with_pair to replace a a condition function with your function

@ribru17
Copy link
Contributor Author

ribru17 commented Aug 2, 2023

After working a bit, now I think it is not as easy. The bracket issue breaks due to the bracket rule thinking it is not in a quote (even though it is in this new case). So there would have to be some sort of change to the is_in_quotes function. However it may not be as bad as a Python workaround hard code. Maybe the function can take some optional parameter to override the regex with a new regex (e.g. the python prefixed string checker)?

@windwp
Copy link
Owner

windwp commented Aug 7, 2023

@ribru17 Are you try to change the order of rule if you put your rule with f string first.
then you add rule is_in_quote . then i think it should work

@ribru17
Copy link
Contributor Author

ribru17 commented Aug 8, 2023

@windwp Sorry not sure what you mean by that

@windwp
Copy link
Owner

windwp commented Sep 5, 2023

@ribru17 sorry for late response. this PR is merged . I just modify some regex. 8b41fe4 . Thank you

@windwp windwp closed this Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent behavior with Python f-strings
3 participants