|
|
|
|
|
by ndr
2839 days ago
|
|
A() and B() could return two different classes that both support foo and bar methods.
If your refactor is to rename one of those methods for one of the classes this code breaks and it's not trivial to update automatically, is it? |
|
> Eg if I rename a method and elsewhere have `if hasattr(obj, ‘foo’):`
Further, even in the absence of insane dynamic code, it probably isn't possible to automatically make a correct decision without knowing the intent of the original code.
For example, maybe we're renaming the `foo` method of `Fizz` class to `barr`, and currently the program is written such that `is hasattr(obj, 'foo'):` only happens to be called on `Fizz` instances. Is it the case that the programmer only ever intended that code to be called on `Fizz` instances, or did the programmer intend it should operate on all types that have a `foo` attribute, including old-style `Fizz` instances and new types that might be encountered in future? In the former case, we should rewrite the logic to `hasattr(obj, 'barr')`, in the latter case perhaps we should leave it unchanged, so it will no longer trigger after the refactor.
i do agree it should be possible to automatically flag this as "here be something interesting to consider! please intervene and make a manual decision!"