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

simplify code using updated definition API #45

Merged
merged 1 commit into from
Apr 22, 2019

Conversation

dirk-thomas
Copy link
Member

Connect to ros2/rosidl#364.

Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
@dirk-thomas dirk-thomas added the in review Waiting for review (Kanban column) label Apr 19, 2019
@dirk-thomas dirk-thomas self-assigned this Apr 19, 2019
@@ -180,12 +178,7 @@ def constant_value_to_py(type_, value):
if type_.typename == 'bool':
Copy link
Contributor

Choose a reason for hiding this comment

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

@dirk-thomas hmm shouldn't it be 'boolean'? Also, here and everywhere else, why not use BOOLEAN_TYPE?

Copy link
Member Author

Choose a reason for hiding this comment

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

For a single typename it doesn't really make a difference. In cases where the constant represents a set of types it makes sense to use the constant in case the set changes later as well as for readability.

Since there are 100+ cases where single typenames are used as string literals in the various generators I would rather not touch it in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

The linter plugins can catch misspellings of BOOLEAN_TYPE, but not misspellings of 'bool'. I don't think it needs to be done in this PR, just pointing out there is a benefit.

Copy link
Contributor

Choose a reason for hiding this comment

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

I do see the improvement in readability, but if the sets were to ever change, having these variables won't do much against the other 100+ cases were the raw string is used (unless it's pure extension, of course).

In any case, above shouldn't it be 'boolean' comment still applies, or otherwise I don't follow why 'boolean' is used everywhere else when checking BasicType.typename attributes.

Copy link
Member Author

@dirk-thomas dirk-thomas Apr 22, 2019

Choose a reason for hiding this comment

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

In any case, above shouldn't it be 'boolean' comment still applies

Absolutely, obviously we currently don't have any boolean constants 😉. Adding one make the code fall through to the exception. I created a follow PR to fix the behavior (since this doesn't aim to change any behavior): #46.

@@ -194,7 +187,7 @@ def constant_value_to_py(type_, value):
if type_.typename == 'octet':
Copy link
Contributor

Choose a reason for hiding this comment

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

@dirk-thomas same about OCTET_TYPE

'int32', 'uint32',
'int64', 'uint64',
):
if type_.typename in INTEGER_TYPES:
return str(value)

if type_.typename == 'char':
Copy link
Contributor

Choose a reason for hiding this comment

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

@dirk-thomas same about an equivalent CHAR_TYPE (I know there's none, I just find it awkward to use the variable in some places and the raw string in others).

Copy link
Member Author

Choose a reason for hiding this comment

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

See #45 (comment). Why should we create a constant for that name (CHAR_TYPE = 'char')? What would be the advantage?

Copy link
Member Author

@dirk-thomas dirk-thomas Apr 22, 2019

Choose a reason for hiding this comment

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

Just copying a comment from @sloretz from above which applies here:

The linter plugins can catch misspellings of BOOLEAN_TYPE, but not misspellings of 'bool'.

Copy link
Contributor

@hidmic hidmic left a comment

Choose a reason for hiding this comment

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

LGTM!

@dirk-thomas dirk-thomas merged commit c02cee1 into master Apr 22, 2019
@delete-merged-branch delete-merged-branch bot deleted the simplification-using-updated-definition-api branch April 22, 2019 19:57
@dirk-thomas dirk-thomas removed the in review Waiting for review (Kanban column) label Apr 22, 2019
jacobperron pushed a commit to ros2/rosidl_runtime_py that referenced this pull request Sep 19, 2019
Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
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

3 participants