Skip to content

Allow mypy to reject incomplete defs for mlagents-envs #2585

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

Merged
merged 2 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix typing for environment.py
  • Loading branch information
Jonathan Harper committed Sep 18, 2019
commit 92d1ef5788c8b41fece4048b9529453abb41cc43
2 changes: 1 addition & 1 deletion ml-agents-envs/mlagents/envs/base_unity_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class BaseUnityEnvironment(ABC):
@abstractmethod
def step(
self,
vector_action: Dict,
vector_action: Optional[Dict] = None,
memory: Optional[Dict] = None,
text_action: Optional[Dict] = None,
value: Optional[Dict] = None,
Expand Down
5 changes: 4 additions & 1 deletion ml-agents-envs/mlagents/envs/brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import io

from mlagents.envs.communicator_objects.agent_info_proto_pb2 import AgentInfoProto
from mlagents.envs.communicator_objects.brain_parameters_proto_pb2 import (
BrainParametersProto,
)
from typing import Dict, List, Optional
from PIL import Image

Expand Down Expand Up @@ -52,7 +55,7 @@ def __str__(self):
)

@staticmethod
def from_proto(brain_param_proto):
def from_proto(brain_param_proto: BrainParametersProto) -> "BrainParameters":
"""
Converts brain parameter proto to BrainParameter object.
:param brain_param_proto: protobuf object.
Expand Down
14 changes: 6 additions & 8 deletions ml-agents-envs/mlagents/envs/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
class UnityEnvironment(BaseUnityEnvironment):
SCALAR_ACTION_TYPES = (int, np.int32, np.int64, float, np.float32, np.float64)
SINGLE_BRAIN_ACTION_TYPES = SCALAR_ACTION_TYPES + (list, np.ndarray)
SINGLE_BRAIN_TEXT_TYPES = (str, list, np.ndarray)
SINGLE_BRAIN_TEXT_TYPES = list

def __init__(
self,
Expand Down Expand Up @@ -358,11 +358,11 @@ def reset(
@timed
def step(
self,
vector_action: Dict,
memory: Optional[Dict] = None,
text_action: Optional[Dict] = None,
value: Optional[Dict] = None,
custom_action: Any = None,
vector_action: Dict[str, np.ndarray] = None,
memory: Optional[Dict[str, np.ndarray]] = None,
text_action: Optional[Dict[str, List[str]]] = None,
value: Optional[Dict[str, np.ndarray]] = None,
custom_action: Dict[str, Any] = None,
) -> AllBrainInfo:
"""
Provides the environment with an action, moves the environment dynamics forward accordingly,
Expand Down Expand Up @@ -498,8 +498,6 @@ def step(
else:
if text_action[brain_name] is None:
text_action[brain_name] = [""] * n_agent
if isinstance(text_action[brain_name], str):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note this is an actual functional change. Requires that if we are given a text_action that it will be a Dict[str, List[str]]. Otherwise the types will be inconsistent. I don't believe we use this feature but I thought it was worth noting.

text_action[brain_name] = [text_action[brain_name]] * n_agent
if brain_name not in custom_action:
custom_action[brain_name] = [None] * n_agent
else:
Expand Down