Skip to content

Could not find name ... - when using a constant as a default value in a class method #1074

@kilroy42

Description

@kilroy42

Describe the Bug

class Object:
    BOOK = 1
    CHAIR = 2
    HOUSE = 3

    def __init__(self, typ: int = BOOK):
        self.typ = typ

print(Object().typ)

This is correct Python code, but it fails with the following error in pyrefly:

ERROR 6:35-39: Could not find name BOOK [[unknown-name](https://pyrefly.org/en/docs/error-kinds/#unknown-name)]

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIAxlKnHAAQDy2AVjJQC6IA669-9AEKNGAaXoBeegEZeA%2BgGEAEgEEAkgCVJ9AExyBSxgFUAygFFtAZl77%2BmGGHoB9JxHQQOLgBRwYUMAA09BykxIj0bhzawmIAlDx88gK%2B-oQhxNrpNui8xABOkV7MbJxesWmhsbwgASAArhzQcCTkiCAAxPRGjVAepPRgdeicELjocNn2jmC4eQC2qJ7odXPYMHle%2BOGRsfQAtAB89HAceQnyeTAcdXl8YNwgAHIra2f0wPgAvg-Vn7WoIwAbjAAGLQGAUNBYPBEMggT5AA&version=3.12

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

Labels

UserBugs reported by external users that should be prioritisedstaletypechecking

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions