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

Fix quoted strings for new flake8-quote check. #42

Merged
merged 1 commit into from
Apr 19, 2019

Conversation

clalancette
Copy link
Contributor

Note that for generated code, we unconditionally disable the
flake8-quote check Q003 (Change outer quotes to avoid escaping
inner quotes). For non-string types, this will have no effect.
For string types, it could be fairly expensive to scan strings
for single or double quotes. The expense just doesn't seem
worth it and the resulting return value won't be exactly what
the user typed into their .msg file.

Signed-off-by: Chris Lalancette clalancette@openrobotics.org

Connects to ros2/build_farmer#179

@clalancette clalancette added the in progress Actively being worked on (Kanban column) label Apr 18, 2019
@clalancette
Copy link
Contributor Author

CI run is in ros2/build_farmer#179 (comment)

@@ -140,7 +140,7 @@ for member in message.structure.members:
@[end for]@
@[for member in message.structure.members]@
@[ if member.has_annotation('default')]@
'@(member.name.upper())__DEFAULT': @(value_to_py(member.type, member.get_annotation_value('default')['value'])),
'@(member.name.upper())__DEFAULT': @(value_to_py(member.type, member.get_annotation_value('default')['value'])), # noqa: Q003
Copy link
Member

Choose a reason for hiding this comment

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

Instead of applying the warning suppression to any kind of content I would suggest to update the primitive_value_to_py() function instead to use the proper quoting.

Same below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is figuring out the proper quoting. To do that, we actually have to walk the entire string and see whether there are any embedded single or double quotes, and then use the opposite. We'll also need to handle escaped quotes properly. In some cases, we won't be able to figure out one, so we'll still have to arbitrarily choose one.

It just doesn't seem worth it either for development time or for runtime. What does the check really buy us?

Copy link
Member

Choose a reason for hiding this comment

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

That the generated code follows our code style guidelines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But that's just not a good enough reason, particularly for generated code, in my opinion. All of this stuff has a cost in terms of time and complexity, and doing busywork like this just doesn't seem to be a good use of either.

Copy link
Member

Choose a reason for hiding this comment

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

I simply implemented the logic in a couple of minutes: see #43

@clalancette clalancette added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Apr 18, 2019
Note that for generated code, we unconditionally disable the
flake8-quote check Q003 (Change outer quotes to avoid escaping
inner quotes).  For non-string types, this will have no effect.
For string types, it could be fairly expensive to scan strings
for single or double quotes.  The expense just doesn't seem
worth it and the resulting return value won't be exactly what
the user typed into their .msg file.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
@clalancette
Copy link
Contributor Author

All right, with #43 going in, we just need the changes to the test strings here, and we'll get rid of all of the flake8 warnings. So this is ready for another review.

@clalancette clalancette merged commit def04fb into master Apr 19, 2019
@delete-merged-branch delete-merged-branch bot deleted the flake8-quote-fixes branch April 19, 2019 15:28
@clalancette clalancette removed the in review Waiting for review (Kanban column) label Apr 19, 2019
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