You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the user instantiates multiple Distance objects, the descriptors will interfere with each other.
There are two (and-a-half) ways to fix this:
Attach a weakref.WeakKeyDictionary to instances of Meter. Use instance as the key and value as the value. This has the disadvantage that Distance must be hashable and probably should not override __eq__().
Place the information in an attribute of the Distance objects. This has the disadvantage of requiring cooperation between the Distance class and the Meter class. This requirement can be eased with the use of a metaclass, but never truly eliminated.
(variation of 2) Turn Distance.meter into a @property (or raw attribute) and delete the Meter class entirely.
The text was updated successfully, but these errors were encountered:
If the user instantiates multiple
Distance
objects, the descriptors will interfere with each other.There are two (and-a-half) ways to fix this:
weakref.WeakKeyDictionary
to instances ofMeter
. Useinstance
as the key andvalue
as the value. This has the disadvantage thatDistance
must be hashable and probably should not override__eq__()
.Distance
objects. This has the disadvantage of requiring cooperation between theDistance
class and theMeter
class. This requirement can be eased with the use of a metaclass, but never truly eliminated.Distance.meter
into a@property
(or raw attribute) and delete theMeter
class entirely.The text was updated successfully, but these errors were encountered: