I have a Python function (3.13): [code] Pylance is complaining: Call expression not…
- User
I have a Python function (3.13):
def get_cands(term: str) -> list[tuple(str, str)]:Pylance is complaining:
Call expression not allowed in type expressionandExpected 1 positional argument - Assistant
The error messages you're seeing are related to how you're specifying the return type annotation in your Python function. In Python 3.13, the correct way to annotate a list of tuples containing strings would be:
def get_cands(term: str) -> list[tuple[str, str]]:The issues in your original code are:
- You're using
strinstead ofstrin the tuple annotation (though this might have been a typo in your question) - The main problem is that you're using parentheses
()in the type annotation, which is incorrect syntax for type hints. You should use square brackets[]for the list type and square brackets for the tuple type as well.
The correct syntax is:
list[...]for liststuple[...]for tuplesstrfor strings (no parentheses)
If you're using Python 3.9+, you can also use the more modern syntax with
listandtupledirectly (without importing fromtyping):def get_cands(term: str) -> list[tuple[str, str]]: # function implementation return []If you need to support older Python versions (pre-3.9), you would need to import these from
typing:from typing import List, Tuple def get_cands(term: str) -> List[Tuple[str, str]]: # function implementation return []But since you mentioned Python 3.13, the first version is perfectly valid.
- You're using
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.