Skip to content

Strip leftover attr.ib() sentinels when these= is passed - #1614

Open
gyanu2507 wants to merge 1 commit into
python-attrs:mainfrom
gyanu2507:fix/these-leftover-ib-sentinels
Open

Strip leftover attr.ib() sentinels when these= is passed#1614
gyanu2507 wants to merge 1 commit into
python-attrs:mainfrom
gyanu2507:fix/these-leftover-ib-sentinels

Conversation

@gyanu2507

Copy link
Copy Markdown

Summary

If these= is passed, class-body attr.ib()s are not collected as fields. They were also not deleted, so C.b could be a private _CountingAttr instead of missing.

I still do not collect those as fields. I only strip leftover sentinels so they cannot leak.

Fixes #621

Pull Request Checklist

  • I acknowledge this project's AI policy.
  • This pull request is not from my main branch.
  • There's tests for all new and changed code.
  • Changes or additions to public APIs are reflected in our type stubs (files ending in .pyi).
    • ...and used in the stub test file typing_tests/baseline.py or, if necessary, typing_tests/mypy.py.
    • If they've been added to attr/__init__.pyi, they've also been re-imported in attrs/__init__.pyi.
  • The documentation has been updated.
    • New functions/classes have to be added to docs/api.rst by hand.
    • Changes to the signatures of @attr.s() and @attrs.define() have to be added by hand too.
    • Changed/added classes/methods/functions have appropriate versionadded, versionchanged, or deprecated directives.
    • Documentation in .rst and .md files is written using semantic newlines.
  • Changes have news fragments in changelog.d.

these= skips collecting class-body fields, but those attr.ib() objects stayed on the class. Accessing them then returned a private _CountingAttr instead of a missing or real attribute.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Passing these=d to attr.s skips attributes defined in class body

1 participant