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

Use variable typing in comments to support python 3.5 #81

Merged
merged 7 commits into from
Jun 18, 2018

Conversation

dhood
Copy link
Member

@dhood dhood commented Jun 17, 2018

Fixes #78

This fixes the build on xenial.

@wjwwood there are a few lines that are too long (https://ci.ros2.org/job/ci_linux/4703/testReport/) but I haven't got mypy setup to check what wrapping will be supported. What invocation do you use? I get Can't find package 'launch' when calling python3 -m mypy --package launch...

@dhood dhood added the in progress Actively being worked on (Kanban column) label Jun 17, 2018
@dhood dhood added this to the bouncy milestone Jun 17, 2018
@dhood dhood self-assigned this Jun 17, 2018
@wjwwood
Copy link
Member

wjwwood commented Jun 17, 2018

Not sure let me check my integration into my editor.

@wjwwood
Copy link
Member

wjwwood commented Jun 17, 2018

I'm using --ignore-missing-imports.

sigkill_timeout: SomeSubstitutionsType = LaunchConfiguration('sigkill_timeout', default=5),
prefix: Optional[SomeSubstitutionsType] = None,
output: Optional[Text] = None,
log_cmd: bool = False,
Copy link
Member

Choose a reason for hiding this comment

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

I thought these kinds worked in Python3.5?

Copy link
Member Author

Choose a reason for hiding this comment

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

oh, maybe I went overkill. I'll check this afternoon.

@dhood dhood force-pushed the commented_variable_typing branch from 6fbe7b7 to 3f71bfc Compare June 18, 2018 02:57
@dhood
Copy link
Member Author

dhood commented Jun 18, 2018

OK @wjwwood you were right and I had more changes than necessary before. It's been reduced to the minimal diff, which does include some code changes, if you could check them thanks (the changes are in individual commits).

@dhood dhood requested a review from wjwwood June 18, 2018 03:05
@dhood dhood added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Jun 18, 2018
)
return [msg]
elif is_a(action, RegisterEventHandler):
result = ["RegisterEventHandler('{}'):".format(action.event_handler)]
result.extend(indent(format_event_handler(action.event_handler)))
typed_action2 = cast(RegisterEventHandler, action)
Copy link
Member Author

Choose a reason for hiding this comment

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

mypy wasn't happy with reuse of the same variable name as above (even though they're in different branches)...

@@ -100,7 +103,7 @@ def format_event_handler(event_handler: EventHandler) -> List[Text]:
"""Return a text representation of an event handler."""
if hasattr(event_handler, 'describe'):
# TODO(wjwwood): consider supporting mode complex descriptions of branching
description, entities = event_handler.describe()
description, entities = event_handler.describe() # type: ignore
Copy link
Member Author

Choose a reason for hiding this comment

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

mypy was complaining about that EventHandler doesn't have a describe method: I think that ignoring it is the appropriate thing to do here.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, the correct fix is to have an empty describe method on the EventHandler subclass. This is fine for now.

@dhood
Copy link
Member Author

dhood commented Jun 18, 2018

xenial Build Status
bionic Build Status

Copy link
Member

@wjwwood wjwwood left a comment

Choose a reason for hiding this comment

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

Thanks for following through on this and for fixing up the files with unrelated mypy violations (I only added mypy to my editor about half way through the implementation).

@@ -55,7 +55,7 @@ class TimerAction(Action):
def __init__(
self, *,
period: Union[float, SomeSubstitutionsType],
actions: Iterable[LaunchDescriptionEntity],
actions: Iterable[LaunchDescriptionEntity]
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need to do anything here (i.e. not blocking merge of this), but just so we're on the same page, this trailing comma was intentional. The idea being that it is allowed and ok style and it would reduce the diff if you needed to add more arguments in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I know that we do it sometimes intentionally (thanks for the explanation though :) ) but it was causing syntax errors with coverage:

launch/actions/execute_process.py:37: in <module>
    from .timer_action import TimerAction
E     File "/home/dhood/ros2_ws/src/ros2/launch/launch/launch/actions/timer_action.py", line 59
E       ) -> None:
E       ^
E   SyntaxError: invalid syntax

(presumably something unique to __init__s)

Copy link
Member Author

@dhood dhood Jun 18, 2018

Choose a reason for hiding this comment

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

this looks like the python ticket, for the curious! (fixed in 3.6) https://bugs.python.org/issue9232

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, weird. :)

@@ -100,7 +103,7 @@ def format_event_handler(event_handler: EventHandler) -> List[Text]:
"""Return a text representation of an event handler."""
if hasattr(event_handler, 'describe'):
# TODO(wjwwood): consider supporting mode complex descriptions of branching
description, entities = event_handler.describe()
description, entities = event_handler.describe() # type: ignore
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, the correct fix is to have an empty describe method on the EventHandler subclass. This is fine for now.

@dhood dhood merged commit fb896f2 into master Jun 18, 2018
@dhood dhood deleted the commented_variable_typing branch June 18, 2018 04:28
@dhood dhood removed the in review Waiting for review (Kanban column) label Jun 18, 2018
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.

Typing annotations of variables used in launch only available for python 3.6+
2 participants