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:
https://github.com/facebook/pyrefly/blob/47f5efe3397a6f9881e5b3398fcd86dc96ed9158/conformance/third_party/dataclasses_slots.py#L24-L25

Sandbox Link

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

(Only applicable for extension issues) IDE Information

No response

Activity

  1. 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(...)].

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

    @Adist319
    Contributor

    I can take a look at this!

  5. rchen152 commented on Jan 7, 2026

    @rchen152
    ContributorAuthor

    Assigned, thank you!

  6. Adist319 commented on Jan 7, 2026

    @Adist319
    Contributor

    PR created here: #2029

  7. added
    help wantedLarger than "good first issue", but still well-defined and ready for someone to pick up
    on Feb 5, 2026
  8. 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