Skip to content

Commit

Permalink
remove pytype annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
m-vdb committed Oct 14, 2020
1 parent f1f1c01 commit 7fa00f4
Show file tree
Hide file tree
Showing 44 changed files with 109 additions and 116 deletions.
2 changes: 1 addition & 1 deletion rasa/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def print_version() -> None:

python_version, os_info = sys.version.split("\n")
try:
from rasax.community.version import __version__ # pytype: disable=import-error
from rasax.community.version import __version__ # rasa-16-to-rasa-17

rasa_x_info = __version__
except ModuleNotFoundError:
Expand Down
2 changes: 1 addition & 1 deletion rasa/cli/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,4 @@ def _get_valid_config(
)
sys.exit(1)

return config # pytype: disable=bad-return-type
return config # rasa-16-to-rasa-17
2 changes: 1 addition & 1 deletion rasa/cli/x.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def _get_credentials_and_endpoints_paths(
def run_locally(args: argparse.Namespace):
try:
# noinspection PyUnresolvedReferences
from rasax.community import local # pytype: disable=import-error
from rasax.community import local # rasa-16-to-rasa-17
except ModuleNotFoundError:
raise MissingDependencyException(
f"Rasa X does not seem to be installed, but it is needed for this CLI command."
Expand Down
9 changes: 5 additions & 4 deletions rasa/core/actions/loops.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from rasa.shared.core.trackers import DialogueStateTracker


class LoopAction(Action, ABC): # pytype: disable=base-class-error
class LoopAction(Action, ABC): # rasa-16-to-rasa-17
async def run(
self,
output_channel: "OutputChannel",
Expand Down Expand Up @@ -43,13 +43,14 @@ async def is_activated(
tracker: "DialogueStateTracker",
domain: "Domain",
) -> bool:
# pytype: disable=attribute-error
# rasa-16-to-rasa-17
return tracker.active_loop_name == self.name()
# pytype: enable=attribute-error

# rasa-16-to-rasa-17

# default implementation checks if form active
def _default_activation_events(self) -> List[Event]:
return [ActiveLoop(self.name())] # pytype: disable=attribute-error
return [ActiveLoop(self.name())] # rasa-16-to-rasa-17

async def activate(
self,
Expand Down
11 changes: 7 additions & 4 deletions rasa/core/channels/botframework.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ async def send_elements(
async def send_custom_json(
self, recipient_id: Text, json_message: Dict[Text, Any], **kwargs: Any
) -> None:
# pytype: disable=attribute-error
# rasa-16-to-rasa-17
json_message.setdefault("type", "message")
json_message.setdefault("recipient", {}).setdefault("id", recipient_id)
json_message.setdefault("from", self.bot)
Expand All @@ -161,7 +161,9 @@ async def send_custom_json(
).setdefault("alert", "true")
json_message.setdefault("text", "")
await self.send(json_message)
# pytype: enable=attribute-error


# rasa-16-to-rasa-17


class BotFrameworkInput(InputChannel):
Expand All @@ -176,9 +178,10 @@ def from_credentials(cls, credentials: Optional[Dict[Text, Any]]) -> InputChanne
if not credentials:
cls.raise_missing_credentials_exception()

# pytype: disable=attribute-error
# rasa-16-to-rasa-17
return cls(credentials.get("app_id"), credentials.get("app_password"))
# pytype: enable=attribute-error

# rasa-16-to-rasa-17

def __init__(self, app_id: Text, app_password: Text) -> None:
"""Create a Bot Framework input channel.
Expand Down
4 changes: 2 additions & 2 deletions rasa/core/channels/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from rasa.shared.constants import DOCS_BASE_URL, DEFAULT_SENDER_ID

try:
from urlparse import urljoin # pytype: disable=import-error
from urlparse import urljoin # rasa-16-to-rasa-17
except ImportError:
from urllib.parse import urljoin

Expand Down Expand Up @@ -318,7 +318,7 @@ def latest_output(self) -> Optional[Dict[Text, Any]]:
return None

async def _persist_message(self, message: Dict[Text, Any]) -> None:
self.messages.append(message) # pytype: disable=bad-return-type
self.messages.append(message) # rasa-16-to-rasa-17

async def send_text_message(
self, recipient_id: Text, text: Text, **kwargs: Any
Expand Down
5 changes: 3 additions & 2 deletions rasa/core/channels/facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,14 @@ def from_credentials(cls, credentials: Optional[Dict[Text, Any]]) -> InputChanne
if not credentials:
cls.raise_missing_credentials_exception()

# pytype: disable=attribute-error
# rasa-16-to-rasa-17
return cls(
credentials.get("verify"),
credentials.get("secret"),
credentials.get("page-access-token"),
)
# pytype: enable=attribute-error

# rasa-16-to-rasa-17

def __init__(self, fb_verify: Text, fb_secret: Text, fb_access_token: Text) -> None:
"""Create a facebook input channel.
Expand Down
2 changes: 1 addition & 1 deletion rasa/core/channels/hangouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class HangoutsInput(InputChannel):
def from_credentials(cls, credentials: Optional[Dict[Text, Any]]) -> InputChannel:

if credentials:
return cls(credentials.get("project_id")) # pytype: disable=attribute-error
return cls(credentials.get("project_id")) # rasa-16-to-rasa-17

return cls()

Expand Down
5 changes: 3 additions & 2 deletions rasa/core/channels/mattermost.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def from_credentials(cls, credentials: Optional[Dict[Text, Any]]) -> InputChanne
if credentials is None:
cls.raise_missing_credentials_exception()

# pytype: disable=attribute-error
# rasa-16-to-rasa-17
if credentials.get("pw") is not None or credentials.get("user") is not None:
rasa.shared.utils.io.raise_deprecation_warning(
"Mattermost recently switched to bot accounts. 'user' and 'pw' "
Expand All @@ -148,7 +148,8 @@ def from_credentials(cls, credentials: Optional[Dict[Text, Any]]) -> InputChanne
token = credentials.get("token")

return cls(credentials.get("url"), token, credentials.get("webhook_url"))
# pytype: enable=attribute-error

# rasa-16-to-rasa-17

def __init__(self, url: Text, token: Text, webhook_url: Text) -> None:
"""Create a Mattermost input channel.
Expand Down
2 changes: 1 addition & 1 deletion rasa/core/channels/rasa_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def from_credentials(cls, credentials: Optional[Dict[Text, Any]]) -> InputChanne
if not credentials:
cls.raise_missing_credentials_exception()

return cls(credentials.get("url")) # pytype: disable=attribute-error
return cls(credentials.get("url")) # rasa-16-to-rasa-17

def __init__(self, url: Optional[Text]) -> None:
self.base_url = url
Expand Down
6 changes: 3 additions & 3 deletions rasa/core/channels/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def on_message_wrapper(
)
await on_new_message(message)

await queue.put("DONE") # pytype: disable=bad-return-type
await queue.put("DONE") # rasa-16-to-rasa-17

async def _extract_sender(self, req: Request) -> Optional[Text]:
return req.json.get("sender", None)
Expand Down Expand Up @@ -82,7 +82,7 @@ async def stream(resp: Any) -> None:
await resp.write(json.dumps(result) + "\n")
await task

return stream # pytype: disable=bad-return-type
return stream # rasa-16-to-rasa-17

def blueprint(
self, on_new_message: Callable[[UserMessage], Awaitable[None]]
Expand Down Expand Up @@ -159,4 +159,4 @@ def latest_output(self) -> NoReturn:
raise NotImplementedError("A queue doesn't allow to peek at messages.")

async def _persist_message(self, message) -> None:
await self.messages.put(message) # pytype: disable=bad-return-type
await self.messages.put(message) # rasa-16-to-rasa-17
5 changes: 3 additions & 2 deletions rasa/core/channels/rocketchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,14 @@ def from_credentials(cls, credentials: Optional[Dict[Text, Any]]) -> InputChanne
if not credentials:
cls.raise_missing_credentials_exception()

# pytype: disable=attribute-error
# rasa-16-to-rasa-17
return cls(
credentials.get("user"),
credentials.get("password"),
credentials.get("server_url"),
)
# pytype: enable=attribute-error

# rasa-16-to-rasa-17

def __init__(self, user: Text, password: Text, server_url: Text) -> None:

Expand Down
5 changes: 3 additions & 2 deletions rasa/core/channels/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def from_credentials(cls, credentials: Optional[Dict[Text, Any]]) -> InputChanne
if not credentials:
cls.raise_missing_credentials_exception()

# pytype: disable=attribute-error
# rasa-16-to-rasa-17
return cls(
credentials.get("slack_token"),
credentials.get("slack_channel"),
Expand All @@ -138,7 +138,8 @@ def from_credentials(cls, credentials: Optional[Dict[Text, Any]]) -> InputChanne
credentials.get("errors_ignore_retry", None),
credentials.get("use_threads", False),
)
# pytype: enable=attribute-error

# rasa-16-to-rasa-17

def __init__(
self,
Expand Down
5 changes: 3 additions & 2 deletions rasa/core/channels/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,14 @@ def from_credentials(cls, credentials: Optional[Dict[Text, Any]]) -> InputChanne
if not credentials:
cls.raise_missing_credentials_exception()

# pytype: disable=attribute-error
# rasa-16-to-rasa-17
return cls(
credentials.get("access_token"),
credentials.get("verify"),
credentials.get("webhook_url"),
)
# pytype: enable=attribute-error

# rasa-16-to-rasa-17

def __init__(
self,
Expand Down
5 changes: 3 additions & 2 deletions rasa/core/channels/twilio.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,14 @@ def from_credentials(cls, credentials: Optional[Dict[Text, Any]]) -> InputChanne
if not credentials:
cls.raise_missing_credentials_exception()

# pytype: disable=attribute-error
# rasa-16-to-rasa-17
return cls(
credentials.get("account_sid"),
credentials.get("auth_token"),
credentials.get("twilio_number"),
)
# pytype: enable=attribute-error

# rasa-16-to-rasa-17

def __init__(
self,
Expand Down
5 changes: 3 additions & 2 deletions rasa/core/channels/webexteams.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ def from_credentials(cls, credentials: Optional[Dict[Text, Any]]) -> InputChanne
if not credentials:
cls.raise_missing_credentials_exception()

# pytype: disable=attribute-error
# rasa-16-to-rasa-17
return cls(credentials.get("access_token"), credentials.get("room"))
# pytype: enable=attribute-error

# rasa-16-to-rasa-17

def __init__(self, access_token: Text, room: Optional[Text] = None) -> None:
"""Create a Cisco Webex Teams input channel.
Expand Down
4 changes: 2 additions & 2 deletions rasa/core/featurizers/single_state_featurizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def convert_to_dict(feature_states: List[Text]) -> Dict[Text, int]:
self._default_feature_states[ACTIVE_LOOP] = convert_to_dict(domain.form_names)
self.action_texts = domain.action_texts

# pytype: disable=bad-return-type
# rasa-16-to-rasa-17
def _state_features_for_attribute(
self, sub_state: SubState, attribute: Text
) -> Dict[Text, int]:
Expand All @@ -78,7 +78,7 @@ def _state_features_for_attribute(
f"It must be one of '{self._default_feature_states.keys()}'."
)

# pytype: enable=bad-return-type
# rasa-16-to-rasa-17

def _create_features(
self, sub_state: SubState, attribute: Text, sparse: bool = False
Expand Down
8 changes: 3 additions & 5 deletions rasa/core/nlg/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,19 @@ def _create_from_endpoint_config(
domain = domain or Domain.empty()

if endpoint_config is None:
from rasa.core.nlg import ( # pytype: disable=pyi-error
from rasa.core.nlg import ( # rasa-16-to-rasa-17
TemplatedNaturalLanguageGenerator,
)

# this is the default type if no endpoint config is set
nlg = TemplatedNaturalLanguageGenerator(domain.templates)
elif endpoint_config.type is None or endpoint_config.type.lower() == "callback":
from rasa.core.nlg import ( # pytype: disable=pyi-error
CallbackNaturalLanguageGenerator,
)
from rasa.core.nlg import CallbackNaturalLanguageGenerator # rasa-16-to-rasa-17

# this is the default type if no nlg type is set
nlg = CallbackNaturalLanguageGenerator(endpoint_config=endpoint_config)
elif endpoint_config.type.lower() == "template":
from rasa.core.nlg import ( # pytype: disable=pyi-error
from rasa.core.nlg import ( # rasa-16-to-rasa-17
TemplatedNaturalLanguageGenerator,
)

Expand Down
2 changes: 1 addition & 1 deletion rasa/core/nlg/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from rasa.shared.core.trackers import DialogueStateTracker
from typing import Text, Any, Dict, Optional, List

from rasa.core.nlg import interpolator # pytype: disable=pyi-error
from rasa.core.nlg import interpolator # rasa-16-to-rasa-17
from rasa.core.nlg.generator import NaturalLanguageGenerator

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion rasa/core/policies/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def _add_package_version_info(self, metadata: Dict[Text, Any]) -> None:
for package_name in self.versioned_packages:
try:
p = importlib.import_module(package_name)
v = p.__version__ # pytype: disable=attribute-error
v = p.__version__ # rasa-16-to-rasa-17
metadata[package_name] = v
except ImportError:
pass
Expand Down
4 changes: 2 additions & 2 deletions rasa/core/policies/form_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _modified_states(states: List[State]) -> List[State]:

return [action_before_listen, states[-1]]

# pytype: disable=bad-return-type
# rasa-16-to-rasa-17
def _create_lookup_from_states(
self,
trackers_as_states: List[List[State]],
Expand All @@ -99,7 +99,7 @@ def _create_lookup_from_states(
lookup[feature_key] = active_form
return lookup

# pytype: enable=bad-return-type
# rasa-16-to-rasa-17

def recall(
self, states: List[State], tracker: DialogueStateTracker, domain: Domain
Expand Down
2 changes: 1 addition & 1 deletion rasa/core/policies/rule_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@


if TYPE_CHECKING:
from rasa.core.policies.ensemble import PolicyEnsemble # pytype: disable=pyi-error
from rasa.core.policies.ensemble import PolicyEnsemble # rasa-16-to-rasa-17

logger = logging.getLogger(__name__)

Expand Down
7 changes: 0 additions & 7 deletions rasa/core/policies/ted_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,6 @@ def load(cls, path: Union[Text, Path]) -> "TEDPolicy":
)


# accessing _tf_layers with any key results in key-error, disable it
# pytype: disable=key-error


class TED(TransformerRasaModel):
def __init__(
self,
Expand Down Expand Up @@ -842,6 +838,3 @@ def batch_predict(
)

return {"action_scores": scores}


# pytype: enable=key-error
6 changes: 3 additions & 3 deletions rasa/core/training/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ async def _validate_nlu(

latest_message = latest_user_message(tracker.get("events", [])) or {}

if latest_message.get("text", "").startswith( # pytype: disable=attribute-error
if latest_message.get("text", "").startswith( # rasa-16-to-rasa-17
INTENT_MESSAGE_PREFIX
):
valid = _validate_user_regex(latest_message, intents)
Expand Down Expand Up @@ -1727,5 +1727,5 @@ def run_interactive_learning(
_serve_application(app, file_importer, skip_visualization, conversation_id, port)

if not skip_visualization and p is not None:
p.terminate() # pytype: disable=attribute-error
p.join() # pytype: disable=attribute-error
p.terminate() # rasa-16-to-rasa-17
p.join() # rasa-16-to-rasa-17
2 changes: 1 addition & 1 deletion rasa/jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def chat(


def _display_bot_response(response: Dict):
from IPython.display import Image, display # pytype: disable=import-error
from IPython.display import Image, display # rasa-16-to-rasa-17

for response_type, value in response.items():
if response_type == "text":
Expand Down
Loading

0 comments on commit 7fa00f4

Please sign in to comment.