◐ Shell
clean mode source ↗

Remove questionable dataclass descriptor conformance assertions by BHUVANSH855 · Pull Request #2296 · python/typing

Summary

Remove questionable Desc2 conformance assertions from dataclasses_descriptors.py.

The existing assertions do not align with actual runtime behavior for non-data descriptors in dataclasses:

  • DC2.x and DC2.y raise AttributeError at runtime because no descriptor instance exists in the class dictionary for those fields.
  • dc2.x and dc2.y evaluate to the stored Desc2 instances because non-data descriptors are shadowed by instance attributes.
  • The z case is also subtle due to descriptor access during dataclass default extraction.

Since this behavior is currently under-specified and differs across type checkers and runtime semantics, this PR removes the questionable assertions and replaces them with explanatory comments.

Fixes #2259