Skip to content

Commit

Permalink
fix deprecation warning related to collections.abc
Browse files Browse the repository at this point in the history
Signed-off-by: William Woodall <william@osrfoundation.org>
  • Loading branch information
wjwwood committed Dec 13, 2018
1 parent 2c64252 commit 3a9708f
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 22 deletions.
5 changes: 3 additions & 2 deletions launch/launch/actions/opaque_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""Module for the OpaqueFunction action."""

import collections
import collections.abc
from typing import Any
from typing import Callable
from typing import Dict
Expand Down Expand Up @@ -58,7 +58,8 @@ def __init__(
raise TypeError("OpaqueFunction expected a callable for 'function', got '{}'".format(
type(function)
))
ensure_argument_type(args, (collections.Iterable, type(None)), 'args', 'OpaqueFunction')
ensure_argument_type(
args, (collections.abc.Iterable, type(None)), 'args', 'OpaqueFunction')
ensure_argument_type(kwargs, (dict, type(None)), 'kwargs', 'OpaqueFunction')
self.__function = function
self.__args = [] # type: Iterable
Expand Down
4 changes: 2 additions & 2 deletions launch/launch/actions/timer_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""Module for the TimerAction action."""

import asyncio
import collections
import collections.abc
import logging
from typing import Any # noqa: F401
from typing import cast
Expand Down Expand Up @@ -63,7 +63,7 @@ def __init__(
super().__init__(**kwargs)
period_types = list(SomeSubstitutionsType_types_tuple) + [float]
ensure_argument_type(period, period_types, 'period', 'TimerAction')
ensure_argument_type(actions, collections.Iterable, 'actions', 'TimerAction')
ensure_argument_type(actions, collections.abc.Iterable, 'actions', 'TimerAction')
if isinstance(period, float):
self.__period = normalize_to_list_of_substitutions([str(period)])
else:
Expand Down
5 changes: 3 additions & 2 deletions launch/launch/event_handlers/on_process_exit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

"""Module for OnProcessExit class."""

import collections
import collections.abc
from typing import Callable
from typing import cast
from typing import List # noqa
from typing import Optional
from typing import overload
from typing import Text
Expand Down Expand Up @@ -92,7 +93,7 @@ def __init__(self, *, target_action=None, on_exit, **kwargs) -> None: # noqa: F
pass
else:
# Otherwise, setup self.__actions_on_exit
if isinstance(on_exit, collections.Iterable):
if isinstance(on_exit, collections.abc.Iterable):
for entity in on_exit:
if not isinstance(entity, LaunchDescriptionEntity):
raise ValueError(
Expand Down
5 changes: 3 additions & 2 deletions launch/launch/launch_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import asyncio
import atexit
import collections
import collections.abc
import logging
import signal
import threading
Expand Down Expand Up @@ -186,7 +186,8 @@ async def __process_event(self, event: Event) -> None:
"processing event: '{}' ✓ '{}'".format(event, event_handler))
self.__context._push_locals()
entities = event_handler.handle(event, self.__context)
entities = entities if isinstance(entities, collections.Iterable) else (entities,)
entities = \
entities if isinstance(entities, collections.abc.Iterable) else (entities,)
for entity in [e for e in entities if e is not None]:
from .utilities import is_a_subclass
if not is_a_subclass(entity, LaunchDescriptionEntity):
Expand Down
4 changes: 2 additions & 2 deletions launch/launch/some_actions_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""Module for SomeActionsType type."""

import collections
import collections.abc
from typing import Iterable
from typing import Union

Expand All @@ -28,5 +28,5 @@

SomeActionsType_types_tuple = (
LaunchDescriptionEntity,
collections.Iterable,
collections.abc.Iterable,
)
4 changes: 2 additions & 2 deletions launch/launch/some_substitutions_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""Module for SomeSubstitutionsType type."""

import collections
import collections.abc
from typing import Iterable
from typing import Text
from typing import Union
Expand All @@ -30,5 +30,5 @@
SomeSubstitutionsType_types_tuple = (
str,
Substitution,
collections.Iterable,
collections.abc.Iterable,
)
4 changes: 2 additions & 2 deletions launch/launch/substitutions/launch_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""Module for the LaunchConfiguration substitution."""

import collections
import collections.abc
from typing import Any
from typing import Iterable
from typing import List
Expand Down Expand Up @@ -51,7 +51,7 @@ def __init__(
# convert any items in default that are not a Substitution or str to a str
str_normalized_default = [] # type: List[Union[Text, Substitution]]
definitely_iterable_default = ((),) # type: Iterable[Any]
if isinstance(default, collections.Iterable):
if isinstance(default, collections.abc.Iterable):
definitely_iterable_default = default
else:
definitely_iterable_default = (default,)
Expand Down
4 changes: 2 additions & 2 deletions launch/launch/substitutions/python_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""Module for the PythonExpression substitution."""

import collections
import collections.abc
from typing import List
from typing import Text

Expand All @@ -38,7 +38,7 @@ def __init__(self, expression: SomeSubstitutionsType) -> None:

ensure_argument_type(
expression,
(str, Substitution, collections.Iterable),
(str, Substitution, collections.abc.Iterable),
'expression',
'PythonExpression')

Expand Down
8 changes: 4 additions & 4 deletions launch/launch/utilities/ensure_argument_type_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""Module for the ensure_argument_type() utility function."""

import collections
import collections.abc
import inspect
from typing import Any
from typing import Iterable
Expand All @@ -36,11 +36,11 @@ def ensure_argument_type(
The caller is included in the error message if given and not None.
"""
error_msg_template = "{}xpected '{}' to be one of [{}], but got '{}' of type '{}'"
if not isinstance(types, collections.Iterable) and not isinstance(types, type):
if not isinstance(types, collections.abc.Iterable) and not isinstance(types, type):
raise TypeError(error_msg_template.format(
"'ensure_argument_type()' e",
'types',
'type, collections.Iterable of type',
'type, collections.abc.Iterable of type',
types,
type(types),
))
Expand Down Expand Up @@ -68,7 +68,7 @@ def check_argument(argument, type_var) -> bool:
result |= issubclass(argument.__class__, type_var)
return result

list_of_types = types if isinstance(types, collections.Iterable) else [types]
list_of_types = types if isinstance(types, collections.abc.Iterable) else [types]
if not any(check_argument(argument, type_var) for type_var in list_of_types):
raise TypeError(error_msg_template.format(
'E' if caller is None else "'{}' e".format(caller),
Expand Down
4 changes: 2 additions & 2 deletions launch/test/launch/test_launch_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""Tests for the LaunchDescription class."""

import collections
import collections.abc
import logging
import os

Expand Down Expand Up @@ -103,6 +103,6 @@ class MockLaunchContext:
...

result = ld.visit(MockLaunchContext())
assert isinstance(result, collections.Iterable)
assert isinstance(result, collections.abc.Iterable)
for entity in result:
assert isinstance(entity, LaunchDescriptionEntity)

0 comments on commit 3a9708f

Please sign in to comment.