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

dataclass definition: "data class fields without default value cannot appear after data fields with default values" #162

Closed
steersbob opened this issue Jul 23, 2020 · 2 comments
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@steersbob
Copy link

Environment data

  • Language Server version: 2020.7.3 (pyright 5004efe5)
  • OS and version: Ubuntu 20.04
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.7.7

Expected behaviour

It being possible to define a dataclass using both uninitialized fields, and fields with a default value.

Actual behaviour

The below snippet has a dataclass field with a default value above fields with init=False.
The definitions for the uninitialized fields generate a Pylance error.

(variable) reset_reason: str
Data class fields without default value cannot appear after data fields with default values

Logs

https://termbin.com/15k2

Code Snippet / Additional information

from dataclasses import dataclass, field

@dataclass
class HandshakeMessage:
    reset_reason_hex: str
    reset_data_hex: str
    device_id: str = field(default='')
    reset_reason: str = field(init=False)
    reset_data: str = field(init=False)

    def __post_init__(self):
        reset_reason = 'calculated value'
        reset_data = 'calculated value'
@erictraut
Copy link
Contributor

Thanks for the bug report. This will be fixed in the next version of Pylance.

@erictraut erictraut added bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version labels Jul 23, 2020
@jakebailey
Copy link
Member

jakebailey commented Jul 29, 2020

This issue has been fixed in version 2020.7.4, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202074-29-july-2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants