Skip to content

behaviour of default values for class attributes differs from CPython #814

Closed
python/mypy
#10798
@jbruechert

Description

If class attributes are used to store constants, it seems impossible to get the value after the file was compiled using mypyc.

Test case:

class Constants:
        RED: str = "red"
        BLUE: str = "blue"
        GREEN: str = "green"

def main():
        print(Constants.RED)

Result:

mypyc:

<attribute 'RED' of 'Constants' objects>

cpython:

red

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions