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

Add smoke tests for bytes literals and recursive f-strings #134

Merged
merged 4 commits into from Oct 29, 2023

Conversation

PeterJCLaw
Copy link
Collaborator

Coverage of the related codepaths was low within the main unit-test suite, which this aims to help with. These tests are admittedly not great, however should catch any glaring issues.

@PeterJCLaw PeterJCLaw force-pushed the more-bytes-string-coverage branch 2 times, most recently from 97df274 to 1326938 Compare October 27, 2023 23:03
@PeterJCLaw
Copy link
Collaborator Author

Somewhat baffled by the coverage apparently decreasing here!

@PeterJCLaw PeterJCLaw marked this pull request as ready for review October 27, 2023 23:24
'x = (f"Wobble {f"{func(kwarg=f"{boo!r}")}"!r}.",)',
)

self.assertEqual(m.view_nodes_at(1, 6), {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also check one or both of the inner f-strings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1c42c83 does this to an extent. We don't seem to get the full details of the inner nodes though. I'm not sure if that's expected.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that's sort of expected pre-3.12 but it's also sort of a bug in 3.12 where getting the tokens becomes possible. ASTText can deal with f-strings, but the package is called asttokens...so if you're willing to look into this, search for include_joined_str.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'd seen that argument to the iter_children_* functions. That's the reason for using node.values over the view_nodes_at approach in the below assertion. Perhaps I'm misunderstanding, but I think the lack of text is coming from the calls to ASTTokens.get_text_positions where the implementations don't return useful values for f-strings (due to not having a first_token). Checking ASTText.get_text_positions's behaviour might be useful, though I'm assuming that that's covered elsewhere.

I'm not sure what you're suggesting be investigated/potentially changed here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm suggesting that in 3.12+, MarkTokens should start attaching first_token to inner f-string nodes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. That feels worthwhile, but perhaps a bit out of the scope of this PR? My main goal here was to add some lightweight coverage for things that #132 seemed to show weren't covered by unit tests.

Having a very quick look, just adding include_joined_str=True in a few places doesn't seem to pass the tests, so this would probably need a deeper dive really.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, please just add a comment explaining the situation with a TODO, because the assertion is indeed hard to understand.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 736d4e3 sufficiently clear?

Coverage of the related codepaths was low within the main unit-test
suite, which this aims to help with. These tests are admittedly not
great, however should catch any glaring issues.
This demonstrates what (little) information we do get about the
child nodes within the JoinedStr.
@alexmojaki
Copy link
Contributor

Thanks again for all your contributions!

@alexmojaki alexmojaki merged commit b8ddec2 into gristlabs:master Oct 29, 2023
24 checks passed
@PeterJCLaw PeterJCLaw deleted the more-bytes-string-coverage branch October 29, 2023 21:49
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.

None yet

2 participants