this is my python code and as you can see the variable choics
that I’m trying to define and give some value keeps showing an error “is not accessed Pylance” in VS,
the error is in this line: choice = tracker.get_slot("customer_choice")
and this is the code:
from typing import Any, Text, Dict, List from rasa_sdk import Action, Tracker from rasa_sdk.executor import CollectingDispatcher class ActionConfirmOrder(Action): def name(self) -> Text: return "action_confirm_order" cus_choice = "pizza" def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: choice = tracker.get_slot("customer_choice") dispatcher.utter_message(text="Your order is {choice}n it will be ready within 10min") return []
I’m using the code in the file actions.py in RASA
demo files in case you know anything about RASA
so if anyone knows what is the problem and can help me. thank you
Advertisement
Answer
This is a standard linter error letting you know that you’ve declared a variable without using it — sometimes it indicates a typo in your code, or an opportunity to clean up dead code.
If you see this error and you think you are using the variable, look very carefully at the line of code where you’re using it, and you’ll probably find a subtle problem around scoping, or a typo in the variable name, or something like that.
In this case, the typo is that your f-string is missing its f
.
dispatcher.utter_message(text="Your order is {choice}n it will be ready within 10min")
Change text="Your order is {choice}..."
to text=f"Your order is {choice}..."
so that choice
will get used in generating the string. Without the f
before the string, {choice}
will be rendered as literally "{choice}"
and your choice
value doesn’t get used for anything.