pylint-bot / pylint-unofficial

UNOFFICIAL playground for pylint github migration
0 stars 0 forks source link

Add "dynamic-modules" option to allow for checking member attributes dynamically (patch attached) #413

Open pylint-bot opened 9 years ago

pylint-bot commented 9 years ago

Originally reported by: Czarek Tomczak (BitBucket: Czarek, GitHub: @Czarek?)


I have this code that uses the wxPython library:

#!python

import wx
frame = wx.Frame(None, -1, "Hello World")

Pylint will throw an error:

#!text
E: 15,15: Module 'wx' has no 'Frame' member (no-member)

A similar issue for the numpy library was reported in the past, see Issue 58:

58/

That case was fixed for numpy, but there are still similar issues with many other libraries. There is a "ignore-modules" option, but using it is not a good idea, as it will ignore real problems when accessing non existent members. In a comment by Mykola Sakhno it was proposed to add a "dynamic-modules" option as a solution for this problem.

Attaching the "pylint_1.4.0_dynamic_modules.patch" file. It adds "dynamic-modules" option and a new method visit_getattr_dynamic() in pylint/checkers/typecheck.py > TypeChecker class. I know that this code isn't perfect, but it's a good start, it works.

The .pylintrc rcfile looks like this:

#!text
[TYPECHECK]
ignored-modules=
dynamic-modules=wx,asd.xyz

The example script I'm using tests two cases: a shared package and a local package. See:

#!python
import wx # a package installed to /lib/site-packages/
import asd.xyz # a local package in application's directory
frame = wx.Frame(None, -1, "Hello World")
asd.xyz.Frame(None, -1, "Hello World")

Without the patch this errors appear in pylint:

#!text
E: 15,15: Module 'wx' has no 'Frame' member (no-member)
E: 16,12: Module 'asd.xyz' has no 'Frame' member (no-member)

After applying patch, these errors disappear. All looks to be working fine.

Using pylint 1.4.0 and Python 3.4.2 on Windows 7. The patch should work with Python 2.7 as well.


pylint-bot commented 9 years ago

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):


Thanks for the patch! Could you submit it as a pull request? It's much easier to review that way.

pylint-bot commented 9 years ago

Original comment by Czarek Tomczak (BitBucket: Czarek, GitHub: @Czarek?):


@PCManticore Created pull request #208.

pylint-bot commented 9 years ago

Original comment by Czarek Tomczak (BitBucket: Czarek, GitHub: @Czarek?):


Found another related Issue #357. Looks like in the past there were probably many manual fixes required like the one in this commit. The "dynamic-modules" option might be a solution to such issues in the future.

pylint-bot commented 9 years ago

Original comment by Czarek Tomczak (BitBucket: Czarek, GitHub: @Czarek?):


There is another kind of error message that isn't handled by this patch and which is also caused by dynamic names:

#!python
from wx.core import *

Results in error:

#!text
E: 12, 0: No name 'core' in module 'wx' (no-name-in-module)

But it's strange as later it complains about specific things being imported from wx.core, so it must have found that "core" name somewhat:

#!text
W: 12, 0: Wildcard import wx.core (wildcard-import)
W: 12, 0: Unused import wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING from wildcard import (unused-wildcard-import)
W: 12, 0: Unused import wxEVT_COMMAND_CHOICE_SELECTED from wildcard import (unused-wildcard-import)
W: 12, 0: Unused import EVT_COMBOBOX from wildcard import (unused-wildcard-import)
...