Skip to content
TheChatArchiveThe Chat Archive
gpt-4.1-mini-2025-04-14· OpenAIHugging Face LMArena Human Preference 140K

I have a Python function (3.13): [code] Pylance is complaining: Call expression not…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Mistralmistral-medium-2505’s answer.
  1. 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 expression and Expected 1 positional argument

  2. 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 calling tuple as 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, list and tuple are 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 expression
    • Expected 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.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.