Skip to content

Feature Request: support __slots__ #630

Closed
1 of 1 issue completed
Closed

Description

@rchen152

Describe the Bug

When a class defines __slots__, pyrefly shouldn't allow writing to attributes that aren't specified in __slots__. This is tested in the dataclasses_slots conformance test, which we currently fail:

# This should generate an error because "y" is not in slots.
self.y = 3 # E

Sandbox Link

https://pyrefly.org/sandbox/?code=MYGwhgzhAECCBcAoaLoH00RAewC4Q2gF5oAKAcgA9yAaASmVQBMBTAM3TQEsA7L3DKQgsQbOklSTow0QDpKxaABYATIynSRbWQE9FqlAGJoAFQAWXGBDPYAriCY9yuaACMW0MCBwB3FkyA

(Only applicable for extension issues) IDE Information

No response

Activity

  1. added theissue type on Jul 3, 2025
  2. yangdanny97 commented on Jul 4, 2025

    @yangdanny97
    Collaborator

    I've been thinking about this and __match_args__ which has similar properties.

    I was thinking we should try and compute these while solving class metadata and store it as something better than Type::Tuple([Type::Literal(...), Type::Literal(...)].

  3. added a commit that references this issue on Jul 5, 2025
  4. removed theissue type on Jul 17, 2025
  5. added theissue type on Jul 17, 2025
  6. added this to the V1 Release milestone on Oct 23, 2025
  7. Adist319 commented on Jan 6, 2026

    @Adist319
    Contributor

    I can take a look at this!

  8. rchen152 commented on Jan 7, 2026

    @rchen152
    ContributorAuthor

    Assigned, thank you!

  9. Adist319 commented on Jan 7, 2026

    @Adist319
    Contributor

    PR created here: #2029

  10. added
    help wantedLarger than "good first issue", but still well-defined and ready for someone to pick up
    on Feb 5, 2026
  11. migeed-z commented on Feb 5, 2026

    @migeed-z
    Contributor

    PR created here: #2029

    Thanks a lot! As we discussed, this PR still has some open questions regarding whether the errors it introduced are false positives or not and had not been active for sometime, unless @Adist319 would still like to look into the false positives, I can take it and/or open to the community

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    conformancehelp wantedLarger than "good first issue", but still well-defined and ready for someone to pick uptypechecking

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions