> From: Of Ben Elliston
> Sent: Wednesday, September 28, 2016 6:40 AM
> To: [email protected]
> Subject: [code-quality] false positive for unidiomatic-typecheck?
>
> I am seeing the following message from pylint:
>
> foo.py:311: [C0123(unidiomatic-typecheck), _legend] Using type() instead
of
> isinstance() for a typecheck.
>
> My line is:
> if type(g) not in unique:
Do note that this is the same as
if isinstance(g, tuple(unique)):
Since isinstance() accepts either a type or a tuple or types (not a set,
list, or any other iterable, though).
>
> That is, I am maintaing a list of unique types in a set of objects.
> This isn't a typecheck. Shouldn't the warning only be produced when
> type(x) is compared with type(y)?
>
Actually, that is a typecheck; it's just not one you're used to seeing.
You're checking for the presence of the type of 'g' in a set. Using
`type(x)` is often unidiomatic, and in almost every case (including this
one), you have a better alternative :)
> Thanks, Ben
-Emanuel
_______________________________________________
code-quality mailing list
[email protected]
https://mail.python.org/mailman/listinfo/code-quality