Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Walrus operator causes no overload match for str.join in dataclass #9659

Open
ostr00000 opened this issue Jan 4, 2025 · 0 comments
Open
Labels
bug Something isn't working

Comments

@ostr00000
Copy link

Describe the bug

Pyright reports an error when a walrus operator is used while passing a variable to str.join and then to a dataclass.
The error is: No overloads for "join" match the provided arguments.

Code or Screenshots

from dataclasses import dataclass

@dataclass
class T_dataclass:
    base: list[str]
    joined: str

T_dataclass(
    base=(b := ['abc', 'def']),
    joined=' '.join(b),
)

Similar code with no error

  • when we define variable not in walrus, then there is no error:
b = ['abc', 'def']
T_dataclass(base=b, joined=' '.join(b))
  • when we define normal class instead of dataclass, then there is no error:
class T_normal:
    def __init__(self, base: list[str], joined: str):
        self.base = base
        self.joined = joined

b = ['abc', 'def']
T_normal(base=b, joined=' '.join(b))

T_normal(
    base=(b := ['abc', 'def']),
    joined=' '.join(b),
)

VS Code extension or command-line

Error detected in VS Code by Pylance. Pylance version is 2024.12.1.

Also, the error is replicated in pyright playground for version 1.1.391.

@ostr00000 ostr00000 added the bug Something isn't working label Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant