-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
pylint lacks type-narrowing control-flow knowledge from isinstance
#1162
Comments
Thank you for reporting this issue. The problem here is that pylint cannot understand even simple if blocks, such as this one you linked. Its inference engine tries to infer |
This really would solve so many situations I've encountered recently that are very frustrating. I think it would also be great to be able to use There are times where we need to type hint for |
@RafeSacks About flow analysis, there is rogalski/flow but it's still in phase of very early drafts and not really active recently. I'm not sure if there's much to discuss to be honest. Of course it would be awesome to have those advanced features in Pylint, main obstacle is simply lack of man-hours. |
@RafeSacks What about mypy, which uses |
Thanks for the replies to my comment. @ngrilly: Does pylint take advantage of mypy? The issue I have is that I have to pepper code with pylint ignores. @rogalski: Totally agree re PEP484. The only reason I brought up something for pylint is for users that lag behind the feature. The visual effects industry is mostly on Python 2.7. Python 3.x isn't likely to be widely adopted until VFX Platform 2019 (http://www.vfxplatform.com). Even then we aren't sure yet which version of Python 3.x, so it could be a long wait. I do like the idea of Doc strings as a source of type hinting since this is widely used already (Sphinx and PyCharm for example). and it is mentioned in PEP484 in "Other backwards compatible conventions" (https://www.python.org/dev/peps/pep-0484/#other-backwards-compatible-conventions). I have no idea if existing code can be easily mined for this feature (https://github.com/agronholm/sphinx-autodoc-typehints) though and I understand a lack of man-hours. If I had time I would take a stab. |
Does mypy really use assert isinstance?
I got the impression it was a separate check run during "build", kind of
like pylint or pyflakes.
…On Thu, Oct 19, 2017 at 3:55 AM, Nicolas Grilly ***@***.***> wrote:
@RafeSacks <https://github.com/rafesacks> What about mypy, which uses assert
isinstance() as a type hint?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1162 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AA0yGkPLHexQuAhrfvQ6mSorvfdgDl6cks5styq_gaJpZM4Kur2t>
.
--
Dan Stromberg
|
On Mon, Oct 23, 2017 at 11:28 AM, RafeSacks ***@***.***> wrote:
Thanks for the replies to my comment.
@ngrilly <https://github.com/ngrilly>: Does pylint take advantage of
mypy? The issue I have is that I have to pepper code with pylint ignores.
I used both pylint and mypy on one project. Most of my projects only use
pylint.
I saw a bug on pylint's issue tracker saying that types imported for use
with mypy may be flagged as unused identifiers - but I didn't encounter
that myself.
The project I used both on is at
http://stromberg.dnsalias.org/svn/equivalence-classes/trunk/equivs3-python/
- see the "go2" rule in the Makefile.
I believe pylint wants to eventually have mypy-like features, but they have
to find the time to add them.
@rogalski <https://github.com/rogalski>: Totally agree re PEP484.
…
The only reason I brought up something for pylint is for users that lag
behind the feature. The visual effects industry is mostly on Python 2.7.
Python 3.x isn't likely to be widely adopted until VFX Platform 2019 (
http://www.vfxplatform.com). Even then we aren't sure yet which version
of Python 3.x, so it could be a long wait.
I do like the idea of Doc strings as a source of type hinting since this
is widely used already (Sphinx and PyCharm for example). and it is
mentioned in PEP484 in "Other backwards compatible conventions" (
https://www.python.org/dev/peps/pep-0484/#other-backwards-compatible-
conventions). I have no idea if existing code can be easily mined for
this feature (https://github.com/agronholm/sphinx-autodoc-typehints)
though and I understand a lack of man-hours. If I had time I would take a
stab.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1162 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AA0yGnBTYmJlwz_5Mg8wkVOWeEfK946lks5svNq-gaJpZM4Kur2t>
.
--
Dan Stromberg
|
@RafeSacks I have a limited understanding of pylint, but it looks like it doesn't use mypy. @dstromberg The recommended way to annotate types for mypy is PEP 484, but I have noticed mypy uses assert isinstance(...) as a type hint, even if it's not the recommended notation. |
isinstance
I'm going to suggest treating this issue as the top-level duplicate for requests to understand type-narrowing with |
pylint-dev/astroid#1189 proposes to introduce
For that case, if we return, say, a subclass of |
pylint-dev/astroid#1189 landed. We should welcome a PR that adds |
Steps to reproduce
pylint -E
on a file containing this piece of code:Current behavior
This error message is displayed:
Instance of 'Exception' has no 'foobar' member (no-member)
Expected behavior
No error message at all.
I am aware that this code do not use python good practices. A
except FoobarException as ex
would have been the right thing to do in that particular case.Still, beeing inside the
if
condition implies thatex
type isFoobarException
and not justException
.That would not be the case with the following piece of code for instance:
pylint --version output
The text was updated successfully, but these errors were encountered: