-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
[Enhancement]: subclassing collections.UserDict
over dict
#323
Comments
Thank you @jamesbraza for opening this! I agree, this would be a great check to add. There might be some sneaky reason why some people extend from |
I would also extend this to include |
Closes #323. I am disabling this check by default for 2 reasons: * `isinstance(x, dict)` fails for `UserDict` objects (including `list`/`str`) * Changing `dict` to `UserDict` is not a quick fix, and you will probably have to change your class definition to get the most out of `UserDict` (ie, removing reimplemented methods, something Refurb can't easily detect). Teams that want to enforce this can enable this option, but overall, it is hard to deduce what is/is not proper usage of classes subclassing `dict`.
Closes #323. I am disabling this check by default for 2 reasons: * `isinstance(x, dict)` fails for `UserDict` objects (including `list`/`str`) * Changing `dict` to `UserDict` is not a quick fix, and you will probably have to change your class definition to get the most out of `UserDict` (ie, removing reimplemented methods, something Refurb can't easily detect). Teams that want to enforce this can enable this option, but overall, it is hard to deduce what is/is not proper usage of classes subclassing `dict`.
Oh wow that was quick turnaround, and thank you @dosisod! I guess the |
Overview
There is a built-in data structure
collections.UserDict
that is designed for subclasses ofdict
.However, I don't think many people are aware of
collections.UserDict
, instead I see lots ofdict
subclasses. I propose a rule to suggest this change.This request was made as of
refurb
version1.28.0
.Proposal
Here is basically what the rule would do:
The text was updated successfully, but these errors were encountered: