Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Descriptor example doesn't handle multiple instances #49

Open
NYKevin opened this issue Sep 18, 2014 · 2 comments
Open

Descriptor example doesn't handle multiple instances #49

NYKevin opened this issue Sep 18, 2014 · 2 comments

Comments

@NYKevin
Copy link

NYKevin commented Sep 18, 2014

If the user instantiates multiple Distance objects, the descriptors will interfere with each other.

There are two (and-a-half) ways to fix this:

  1. 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__().
  2. 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.
  3. (variation of 2) Turn Distance.meter into a @property (or raw attribute) and delete the Meter class entirely.
@RafeKettler
Copy link
Owner

thanks for the report @NYKevin, I will take a look soon

@brandjon
Copy link

This is addressed in my pull request from last year. I used @NYKevin's option 2. I'm curious as to why my PR seems to have gone unnoticed.

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

No branches or pull requests

3 participants