-
Notifications
You must be signed in to change notification settings - Fork 750
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
E721: suggest reasonable alternative #882
Comments
Is |
I don't think so (as mentioned above) because it is
I am also not sure what would happen if There is also not really a reason to use this more complicated way - it doesn't have any advantage to the simpler version. |
I believe |
I would like that. I am not 100% sure if it would work by default (I would have to dig into the differences between |
the only way it could differ is if the metaclass for the particular type overrides |
I'm always in favour of more usages of |
@Kaligule Ned Batchelder has a good succinct talk (& accompanying blog post iirc) on this from a while ago that I'm sure is easily searchable |
TL;DR of the blog post:
If types (as returned by |
The gotcha would be if you have a case where some popular library vendors its dependencies and you're also on an Operating System that distributes its own versions of this library with the dependencies unvendored. In that case you might |
@sigmavirus24 Well now I want to ask how you encountered that haha. It's important to identify those rare corner cases though. I think the more pertinent question is whether |
No. |
E721 is there to prevent
type(3) == int
in favour ofisinstance(3, int)
. Thats fine.But it also raises an error for code like
type(a) == type(b)
. This is good code though and I don't know of a better way to test if two values have the same type. Of course you can go forisinstance(a, type(b))
, but that is longer and less readable.I suggest either changing E721 to not match lines like the above or to suggest a reasonable alternative to the line above.
The text was updated successfully, but these errors were encountered: