Conversation
ABCMeta only inspects the object a subclass finally binds to an abstract name; if that object does not report itself as abstract, the name counts as implemented. Nothing checks that a descriptor replacing an abstract one still provides the same components, so a read-write abstract property can be overridden by a read-only one without the subclass losing its instantiability, and the missing setter surfaces only as an AttributeError when the attribute is assigned to. Document that in the abstractmethod section, and cancel the implicature that was reported in the deprecated abstractproperty section by saying outright that borrowing the remaining components from the base class is not the only way to override an abstract property.
…nents (abc) test_descriptors_with_abstractmethod only covers overrides built with property.getter and property.setter, which carry the abstract components of the base property forward. Nothing pinned the behaviour documented in the previous commit: that binding an abstract name to any non-abstract object -- a read-only property, or a plain value -- makes it concrete, whatever the original descriptor provided.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Documentation build overview
|
|
Closing this myself. @picnixz pointed out on #158152 that I have been opening too many at once and that old issues nobody has revived are the wrong ones to pick up unasked — this is one of those, so it should not be sitting in the queue. The branch stays on my fork if the issue ever comes back to life. |
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
Reopened. Closing this was my own overreaction to being told I had too many open, not something anyone asked for. |
Closes #83888, on @gvanrossum's invitation in that thread ("Josh, feel free to submit a PR (make sure it mentions this issue)").
The
abcdocs let a reader conclude that overriding an abstract read-write property obliges the subclass to supply a setter. It does not. Measured onmain:So
Dinstantiates happily and the missing setter surfaces much later, as anAttributeErrorat the assignment.Why, and why this is a docs change
@rhettinger explained the mechanism and ruled out fixing it:
and @gvanrossum agreed and closed it on that basis:
The issue survived as a documentation one, so the text now describes what happens and names that remedy.
Wording
The mechanism is stated as what it actually is, which is not specific to properties:
ABCMetainspects only the object a subclass finally binds to an abstract name, and if that object does not report itself as abstract, the name counts as implemented. Bindingfoo = 3clears the abstraction just as effectively as a read-only property does — a property-shaped explanation would have been too narrow.The
abstractpropertyblock gets a matching sentence, since it is the one place that demonstrated borrowing the remaining components from the base class and so reads as if that were required.Test
test_concrete_override_drops_abstract_componentspins the documented behaviour: the read-only override, its laterAttributeError, and the plain-value override. Without it the prose would be the only record of a behaviour nobody has asserted.It is not tautological — changing the expected
D.__abstractmethods__back to{"foo"}gives 2 failures.No runtime change;
Doc/library/abc.rstandLib/test/test_abc.pyonly, +45 lines, nothing removed. Since the diff includes a test file thedocslabel may not pull inskip newson its own — I do not think aMisc/NEWS.dentry is warranted for a docs-and-test change, but say the word and I will add one.