-
-
Notifications
You must be signed in to change notification settings - Fork 80
Warn when concrete_descendents clobbers classes #1035
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
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1035 +/- ##
==========================================
+ Coverage 89.16% 89.18% +0.01%
==========================================
Files 9 9
Lines 4679 4686 +7
==========================================
+ Hits 4172 4179 +7
Misses 507 507 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@jlstevens the PyPy tests have failed which raised an interesting question. I feel like if we want to fix this for good, we need to update
What do you think? class ClassSelector(Parameter):
...
def get_range(self):
"""
Return the possible types for this parameter's value.
(I.e. return `{name: <class>}` for all classes that are
concrete_descendents() of `self.class_`.)
Only classes from modules that have been imported are added
(see concrete_descendents()).
"""
classes = self.class_ if isinstance(self.class_, tuple) else (self.class_,)
all_classes = {}
for cls in classes:
all_classes.update(concrete_descendents(cls))
d = OrderedDict((name, class_) for name,class_ in all_classes.items())
if self.allow_None:
d['None'] = None
return dEDIT: This is following a discussion started here #1027 (comment) |
|
I don't know the cleanest way to get out of this mess, but presumably it's also worth (briefly) considering a multidict, which would preserve the interface but allow duplicate keys? That might well cause other problems later, of course, if someone tries to use the multidict as a regular dict. |
|
True, I didn't consider multidict until now. I'll chat with Jean-Luc this week more about all this! |
|
Reading this again #1035 (comment), I no longer think that's the right approach as I am not confident that there's a sane way to change the type of what Instead, I'd suggest either:
I might just go for 1) now to unblock this. |
|
Unrelated test failures, merging. |
concrete_descendentsnow warns when class name clobbering is detected. We recommend usingdescendents(cls, concrete=True)instead which returns a list of concrete classes.ClassSelector.get_range()will not warn on clobbering, this is the current, unchanged behavior. Options to fix this would include updating somehow the returned type to a list of tuples, or creating another method likerangethat doesn't suffer from this problem. I'm not going to take care of that now but will record it in an issue.