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
"Arguments missing" for optional arguments in dataclass #893
Comments
Have you tried running this code? When I run this: from dataclasses import dataclass
from typing import Optional
@dataclass
class User:
name: str
age: Optional[int]
user = User(name="Jon") I get this output:
For a field to be actually optional in the dataclass constructor you must give it a default value, in this case probably @dataclass
class User:
name: str
age: Optional[int] = None Which Pylance correctly handles (actually if this was a bug I assume it would be with Pyright not Pylance). |
The notation Pylance is doing the right thing here based on PEP 557. |
If you're interested in following the discussion in the typing-sig, here's a link. |
thanks for the info, using a default value makes sense. |
Environment data
Expected behaviour
Creating an instance of a dataclass without arguments for optional fields will show no error
Actual behaviour
creating an instacnce of a dataclass without arguments for optional fields shows and error "arguments missing"
The text was updated successfully, but these errors were encountered: