gpt-4.1-mini-2025-04-14· OpenAI
LMArena Human Preference 140K
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 issue is with the syntax of the type hint for the return value in your function signature:
def get_cands(term: str) -> list[tuple(str, str)]:What's wrong?
tuple(str, str)is callingtupleas a function, which is not allowed in type annotations.- The correct syntax for a tuple type with two elements is
tuple[str, str](using square brackets, not parentheses). - Also,
listandtupleare generic types and should be subscripted with square brackets[]in type hints.
Corrected function signature:
def get_cands(term: str) -> list[tuple[str, str]]:Explanation:
list[...]means a list of something.tuple[str, str]means a tuple with exactly two elements, both strings.
Summary:
Replace parentheses with square brackets inside the type hint:
def get_cands(term: str) -> list[tuple[str, str]]:This will fix the Pylance errors:
Call expression not allowed in type expressionExpected 1 positional argument
If you want to be compatible with Python versions before 3.9, you can import from
typing:from typing import List, Tuple def get_cands(term: str) -> List[Tuple[str, str]]:But since you mentioned Python 3.13, the built-in generics syntax (
list[...],tuple[...]) is preferred and correct.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.