pylint 1.6.3 reports E1101(no-member) for xml - python

We are using the ElementTree library in our project. This comes from the standard library, but for some reason pylint chokes on it. It always reports an E1101 on any reference on an ElementTree object. Here is a sample bit of code to demonstrate this:
import xml.etree.ElementTree as ET
test = ET.parse('test.xml')
config = test.find('.//configuration')
print(config)
for role in config.findall('.//role'):
print(role)
The output from pylint always throws an E1101:
$ pylint --rcfile=pylint.cfg -E test.py
************* Module orion-scripts.test
E: 7,12: Instance of 'int' has no 'findall' member (no-member)
But the program runs just fine:
$ python test.py
<Element 'role' at 0x1052dfe50>
<Element 'configuration' at 0x1052dfe10>
I found a number of solutions to similar problems, but so far none have worked for this one. I've tried:
Setting an ignored class with ignored-classes=xml.etree.ElementTree
Setting it as a generated member with generated-members=ET
Allowing any extension to run with unsafe-load-any-extension=yes
Nothing has worked and I'm currently just ignoring E1101 messages. However, this is a really bad option and I would much prefer to just ignore this particular class. If it helps, this is the version info for pylint:
$ pylint --version
No config file found, using default configuration
pylint 1.6.3,
astroid 1.4.7
Python 2.7.11 (default, Jan 22 2016, 08:28:37)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]

Related

Adding modules in atom in python

I have the module pygame and tkinter installed on my computer, but I cannot find out how to access them in the text editor atom. I can use them in IDLE by using
import pygame
but when I try to import it in atom it doesn't recognize the module. Anybody know why? All of my other imports work by the way (time, random, etc.) but I think that they work because they come installed with python (right?).
Firstly, atom is a text editor, it does not run python code by itself. So when you say you're trying to "import it in atom", I have to assume you're using an atom plugin that can interpret code. One common plugin for this is "script".
You need to head to the atom settings to check which python install is being used. Do this by first entering atom settings with control+,, then click on "packages" on the navagator, and click on "script" (or whatever plugin you're using to run your code, e.g. script, Hydrogen, atom-runner etc.). In the script settings, click on "view code", which will open the source code of script. On the tree nagivator on the left, navigate to script-->lib-->grammars-->python.coffee
In this coffeescript file, you should find the python interpreter that atom-script is using. For example, since I use anaconda, mine reads:
exports.Python =
'Selection Based':
command: '/home/username/.miniconda3/envs/local35/bin/python'
args: (context) -> ['-u', '-c', context.getCode()]
If you run linux or mac, now you can open a terminal and run
which python
import pygame should theoretically work if the system python matches the one atom is using, so these will probably be different. Just replace the python path in the coffeescript file with the result of which python. If these are already the same, this process should at least give you some clues to further diagnose the issue.
Personally, I recommend the use of Anaconda to keep track of your python environments and modules, it can really help with issues like this.
Also do make sure that python -c "import pygame" works, because if it doesn't, this isn't an atom issue at all.
I'm a new user. John Kealy's answer is what helped solve my Atom 1.40.1 (using Script 3.18.1,) "..module not found" issue. From the Python 3.7 interpreter:
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
My pip list:
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\Users\erica> pip list
Package Version
--------------- -----------
bleak 0.5.0
bricknil-bleak 0.3.1
cycler 0.10.0
kiwisolver 1.1.0
matplotlib 3.1.1
mpmath 1.1.0
numpy 1.16.4
pip 19.2.3
pybluez 0.22
pyparsing 2.4.0
python-dateutil 2.8.0
pythonnet 2.4.0
pyVIP 1.3.0
scipy 1.3.0
setuptools 41.2.0
six 1.12.0
sympy 1.4
virtualenv 16.7.4
wheel 0.33.4
winrt 1.0.19128.1
I right-clicked on the Python interpreter icon and copied the target string from the properties dialog box:
C:\Users\erica\AppData\Local\Programs\Python\Python37\python.exe
From the python.coffee script John mentioned, where "command:" originally read:
exports.Python =
'Selection Based':
command: 'python'
args: (context) -> ['-u', '-c', context.getCode()]
'File Based':
command: 'python'
args: ({filepath}) -> ['-u', filepath]
I then modified to:
exports.Python =
'Selection Based':
command: 'C:/Users/erica/AppData/Local/Programs/Python/Python37/python'
args: (context) -> ['-u', '-c', context.getCode()]
'File Based':
command: 'C:/Users/erica/AppData/Local/Programs/Python/Python37/python'
args: ({filepath}) -> ['-u', filepath]
So now I can have this code in my test.py file:
import bluetooth as bt
for e in bt.__dict__:
print(e)
...and cntrl-shift-b to the results in the Script output window at the bottom of my Atom screen:
[Command: C:/Users/erica/AppData/Local/Programs/Python/Python37/python -u C:\Users\erica\AppData\Local\Programs\Python\Python37\test.py]
__name__
__doc__
__package__
__loader__
__spec__
__path__
__builtins__
__file__
__cached__
sys
os
btcommon
struct
binascii
L2CAP
RFCOMM
PORT_ANY
SDP_SERVER_CLASS
BROWSE_GRP_DESC_CLASS
PUBLIC_BROWSE_GROUP
SERIAL_PORT_CLASS
LAN_ACCESS_CLASS
DIALUP_NET_CLASS
IRMC_SYNC_CLASS
OBEX_OBJPUSH_CLASS
OBEX_FILETRANS_CLASS
IRMC_SYNC_CMD_CLASS
HEADSET_CLASS
CORDLESS_TELEPHONY_CLASS
AUDIO_SOURCE_CLASS
AUDIO_SINK_CLASS
AV_REMOTE_TARGET_CLASS
ADVANCED_AUDIO_CLASS
AV_REMOTE_CLASS
VIDEO_CONF_CLASS
INTERCOM_CLASS
FAX_CLASS
HEADSET_AGW_CLASS
WAP_CLASS
WAP_CLIENT_CLASS
PANU_CLASS
NAP_CLASS
GN_CLASS
DIRECT_PRINTING_CLASS
REFERENCE_PRINTING_CLASS
IMAGING_CLASS
IMAGING_RESPONDER_CLASS
IMAGING_ARCHIVE_CLASS
IMAGING_REFOBJS_CLASS
HANDSFREE_CLASS
HANDSFREE_AGW_CLASS
DIRECT_PRT_REFOBJS_CLASS
REFLECTED_UI_CLASS
BASIC_PRINTING_CLASS
PRINTING_STATUS_CLASS
HID_CLASS
HCR_CLASS
HCR_PRINT_CLASS
HCR_SCAN_CLASS
CIP_CLASS
VIDEO_CONF_GW_CLASS
UDI_MT_CLASS
UDI_TA_CLASS
AV_CLASS
SAP_CLASS
PNP_INFO_CLASS
GENERIC_NETWORKING_CLASS
GENERIC_FILETRANS_CLASS
GENERIC_AUDIO_CLASS
GENERIC_TELEPHONY_CLASS
UPNP_CLASS
UPNP_IP_CLASS
UPNP_PAN_CLASS
UPNP_LAP_CLASS
UPNP_L2CAP_CLASS
VIDEO_SOURCE_CLASS
VIDEO_SINK_CLASS
SDP_SERVER_PROFILE
BROWSE_GRP_DESC_PROFILE
SERIAL_PORT_PROFILE
LAN_ACCESS_PROFILE
DIALUP_NET_PROFILE
IRMC_SYNC_PROFILE
OBEX_OBJPUSH_PROFILE
OBEX_FILETRANS_PROFILE
IRMC_SYNC_CMD_PROFILE
HEADSET_PROFILE
CORDLESS_TELEPHONY_PROFILE
AUDIO_SOURCE_PROFILE
AUDIO_SINK_PROFILE
AV_REMOTE_TARGET_PROFILE
ADVANCED_AUDIO_PROFILE
AV_REMOTE_PROFILE
VIDEO_CONF_PROFILE
INTERCOM_PROFILE
FAX_PROFILE
HEADSET_AGW_PROFILE
WAP_PROFILE
WAP_CLIENT_PROFILE
PANU_PROFILE
NAP_PROFILE
GN_PROFILE
DIRECT_PRINTING_PROFILE
REFERENCE_PRINTING_PROFILE
IMAGING_PROFILE
IMAGING_RESPONDER_PROFILE
IMAGING_ARCHIVE_PROFILE
IMAGING_REFOBJS_PROFILE
HANDSFREE_PROFILE
HANDSFREE_AGW_PROFILE
DIRECT_PRT_REFOBJS_PROFILE
REFLECTED_UI_PROFILE
BASIC_PRINTING_PROFILE
PRINTING_STATUS_PROFILE
HID_PROFILE
HCR_PROFILE
HCR_PRINT_PROFILE
HCR_SCAN_PROFILE
CIP_PROFILE
VIDEO_CONF_GW_PROFILE
UDI_MT_PROFILE
UDI_TA_PROFILE
AV_PROFILE
SAP_PROFILE
PNP_INFO_PROFILE
GENERIC_NETWORKING_PROFILE
GENERIC_FILETRANS_PROFILE
GENERIC_AUDIO_PROFILE
GENERIC_TELEPHONY_PROFILE
UPNP_PROFILE
UPNP_IP_PROFILE
UPNP_PAN_PROFILE
UPNP_LAP_PROFILE
UPNP_L2CAP_PROFILE
VIDEO_SOURCE_PROFILE
VIDEO_SINK_PROFILE
SERVICE_RECORD_HANDLE_ATTRID
SERVICE_CLASS_ID_LIST_ATTRID
SERVICE_RECORD_STATE_ATTRID
SERVICE_ID_ATTRID
PROTOCOL_DESCRIPTOR_LIST_ATTRID
BROWSE_GROUP_LIST_ATTRID
LANGUAGE_BASE_ATTRID_LIST_ATTRID
SERVICE_INFO_TIME_TO_LIVE_ATTRID
SERVICE_AVAILABILITY_ATTRID
BLUETOOTH_PROFILE_DESCRIPTOR_LIST_ATTRID
DOCUMENTATION_URL_ATTRID
CLIENT_EXECUTABLE_URL_ATTRID
ICON_URL_ATTRID
SERVICE_NAME_ATTRID
SERVICE_DESCRIPTION_ATTRID
PROVIDER_NAME_ATTRID
SDP_UUID
UDP_UUID
RFCOMM_UUID
TCP_UUID
TCS_BIN_UUID
TCS_AT_UUID
OBEX_UUID
IP_UUID
FTP_UUID
HTTP_UUID
WSP_UUID
BNEP_UUID
UPNP_UUID
HIDP_UUID
HCRP_CTRL_UUID
HCRP_DATA_UUID
HCRP_NOTE_UUID
AVCTP_UUID
AVDTP_UUID
CMTP_UUID
UDI_UUID
L2CAP_UUID
IAC_GIAC
IAC_LIAC
BluetoothError
is_valid_address
is_valid_uuid
to_full_uuid
sdp_parse_size_desc
sdp_parse_uuid
sdp_parse_int
sdp_parse_data_elementSequence
sdp_parse_data_element
sdp_parse_raw_record
sdp_make_data_element
__version__
_dbg
have_widcomm
dll
sysroot
_msbt
msbt
bt
discover_devices
read_local_bdaddr
lookup_name
BluetoothSocket
advertise_service
stop_advertising
find_service
DeviceDiscoverer
[Finished in 0.417s]
Additionally, from inquiry.py:
import bluetooth
print("performing inquiry...")
nearby_devices = bluetooth.discover_devices(
duration=8, lookup_names=True, flush_cache=True, lookup_class=False)
print("found %d device(s)" % len(nearby_devices))
for addr, name in nearby_devices:
try:
print(" %s - %s" % (addr, name))
except UnicodeEncodeError:
print(" %s - %s" % (addr, name.encode('utf-8', 'replace')))
...and again cntrl-shift-b to the results in the Script output window at the bottom of my Atom screen:
performing inquiry...
found 1 device(s)
98:FD:B4:47:0D:14 - HP Bluetooth Mouse X4000b
[Finished in 10.601s]
Seems that my access to my Python modules is working now.

PyLint not finding class from Google Appengine SDK

We have a Python Application running on Google App Engine. For local development, we have the Google Appengine SDK installed. The setup is a little messed up as the application itself adds things to the sys.path. PyLint of course does not pick up those changes happening somewhere in some function.
I tried cleaning up the PyLint log by adding the Google Appengine SDK to the PYTHONPATH, which worked pretty good. Locally, I can now run PyLint for a specific set of folders and it reports a 10/10 with no errors (but a lot of locally-disabled statements). The same code is reporting exactly 1 issue on our CI system (We use Codeship). The message is Module 'google.appengine.ext.ndb' has no 'JsonProperty' member (no-member).
The Googe Appengine SDK is installed inside the Codeship container and is added to the PYTHONPATH. Other functions/classes from the SDK get picked up correctly. The google.appengine.ext.ndb.init.py looks like this:
"""NDB -- A new datastore API for the Google App Engine Python runtime."""
__version__ = '1.0.10'
__all__ = []
from tasklets import *
__all__ += tasklets.__all__
from model import * # This implies key.*
__all__ += model.__all__
from query import *
__all__ += query.__all__
from context import *
__all__ += context.__all__
The google.appengine.ext.ndb.model.py contains the JsonProperty class and has some magic as well:
# Update __all__ to contain all Property and Exception subclasses.
for _name, _object in globals().items():
if ((_name.endswith('Property') and issubclass(_object, Property)) or
(_name.endswith('Error') and issubclass(_object, Exception))):
__all__.append(_name)
As I said, it works locally but does not on Codeship. Locally, `pylint --version prints
pylint 1.5.0,
astroid 1.4.5
Python 2.7.9 (default, Apr 2 2015, 15:33:21)
[GCC 4.9.2]
while on Codeship, it says
pylint 1.5.0,
astroid 1.4.4
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2]
I am not sure what is going on here. There should be no major differences between Python 2.7.6 and 2.7.9, right? I have no idea how to further debug this either. Any hints are appreciated.

PyCharm PYTHONPATH different in Python Console vs running the GAE development server?

While trying to figure out how to properly import the Google Identity Toolkit into my GAE project I observed that when running the project in PyCharm (v. 4.5.2 pro) the PYTHONPATH is NOT the same as in PyCharm's Python Console.
For example in the Console I properly find the oauth2client library from the GAE SDK (v. 1.9.23):
/usr/bin/python2.7 -u /home/usr_local/pycharm-4.5.2/helpers/pydev/pydevconsole.py 43085 43754
Python 2.7.8 (default, Sep 30 2014, 15:34:38) [GCC]
Type "copyright", "credits" or "license" for more information.
IPython 2.2.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
PyDev console: using IPython 2.2.0
import sys; print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend(['/home/user/src/myapp', '/usr/local/google_appengine', '/usr/local/google_appengine/lib/antlr3', '/usr/local/google_appengine/lib/apiclient', '/usr/local/google_appengine/lib/endpoints-1.0', '/usr/local/google_appengine/lib/yaml-3.10', '/usr/local/google_appengine/lib/markupsafe-0.15', '/usr/local/google_appengine/lib/django-1.3', '/usr/local/google_appengine/lib/requests', '/usr/local/google_appengine/lib/fancy_urllib', '/usr/local/google_appengine/lib/webob_0_9', '/usr/local/google_appengine/lib/graphy', '/usr/local/google_appengine/lib/distutils', '/usr/local/google_appengine/lib/concurrent', '/usr/local/google_appengine/lib/cacerts', '/usr/local/google_appengine/lib/six', '/usr/local/google_appengine/lib/pyasn1', '/usr/local/google_appengine/lib/setuptools-0.6c11', '/usr/local/google_appengine/lib/jinja2-2.6', '/usr/local/google_appengine/lib/portpicker', '/usr/local/google_appengine/lib/django-0.96', '/usr/local/google_appengine/lib/django-1.2', '/usr/local/google_appengine/lib/PyAMF-0.6.1', '/usr/local/google_appengine/lib/sqlcmd', '/usr/local/google_appengine/lib/oauth2client', '/usr/local/google_appengine/lib/uritemplate', '/usr/local/google_appengine/lib/httplib2', '/usr/local/google_appengine/lib/protorpc-1.0', '/usr/local/google_appengine/lib/python-gflags', '/usr/local/google_appengine/lib/rsa', '/usr/local/google_appengine/lib/grizzled', '/usr/local/google_appengine/lib/django-1.5', '/usr/local/google_appengine/lib/ipaddr', '/usr/local/google_appengine/lib/django-1.4', '/usr/local/google_appengine/lib/argparse', '/usr/local/google_appengine/lib/google-api-python-client', '/usr/local/google_appengine/lib/mox', '/usr/local/google_appengine/lib/cherrypy', '/usr/local/google_appengine/lib/prettytable', '/usr/local/google_appengine/lib/webapp2-2.3', '/usr/local/google_appengine/lib/oauth2', '/usr/local/google_appengine/lib/pyasn1_modules', '/usr/local/google_appengine/lib/webapp2-2.5.2', '/usr/local/google_appengine/lib/websocket', '/usr/local/google_appengine/lib/yaml', '/usr/local/google_appengine/lib/docker', '/usr/local/google_appengine/lib/simplejson', '/usr/local/google_appengine/lib/webapp2-2.5.1', '/usr/local/google_appengine/lib/deprecated_enum'])
Python 2.7.8 (default, Sep 30 2014, 15:34:38) [GCC] on linux2
In[2]: from oauth2client import crypt
In[3]: crypt
Out[3]: <module 'oauth2client.crypt' from '/usr/local/google_appengine/lib/oauth2client/oauth2client/crypt.py'>
In[4]:
But when running the project I get:
File "/home/user/src/myapp/main/identitytoolkit/gitkitclient.py", line 47, in <module>
from oauth2client import crypt
ImportStringError: import_string() failed for 'gitkit.GitKitHandler'. Possible reasons are:
- missing __init__.py in a package;
- package or module path not included in sys.path;
- duplicated package or module name taking precedence in sys.path;
- missing module, class, function or variable;
Original exception:
ImportError: No module named oauth2client
I'm also dumping the sys.path before the exception (real paths are displayed, /usr/local/google_appengine is a symlink to /home/usr_local/google_appengine_1.9.23):
ERROR 2015-06-30 18:59:46,199 gitkit.py:13] ['/home/user/src/myapp/main', '/home/usr_local/google_appengine_1.9.23', '/home/usr_local/google_appengine_1.9.23', '/usr/lib64/python2.7', '/usr/lib64/python2.7/lib-dynload', '/home/usr_local/google_appengine_1.9.23/lib/webapp2-2.5.2', '/home/usr_local/google_appengine_1.9.23/lib/jinja2-2.6', '/home/usr_local/google_appengine_1.9.23/lib/pycrypto-2.6', '/home/usr_local/google_appengine_1.9.23/lib/markupsafe-0.15', '/home/usr_local/google_appengine_1.9.23/lib/setuptools-0.6c11', '/home/usr_local/google_appengine_1.9.23/lib/protorpc-1.0', '/home/usr_local/google_appengine_1.9.23/lib/webob-1.1.1', '/home/usr_local/google_appengine_1.9.23/lib/yaml-3.10']
Is there a way to configure PyCharm to apply the same PYTHONPATH from the Console (which is IMHO correct) to the development server execution?
Alternatively - how does PyCharm determine/configure the development server execution path? (I don't mind even configuring the correct path manually if needed).
Donno if relevant, but I've upgraded the PyCharm and GAE SDK versions several times while working on this project.
It turned out that the GAE development server adjusts its own execution path depending on the SDK installation and the executed app code itself.
The failures in my case were caused by incorrect 3rd party lib vendoring in a multi-modules app. I documented my fix here: Is Google Identity Toolkit (v3) compatible with GAE/python sandbox?

Python Snakefood module import generalized failure

I want to run snakefood (an AST-based dependency graph analyser; source code can be found here). My project has a structureinvolving several levels of Python packages, like this:
myproject
|code
|Utils
|AdaptedConfigParser
Configs_Parser.py
...
...
main.py
However, when I start running snakefood on the root directory of my project it claims that it can't find the modules from my Python package being imported:
$ sfood --internal --follow --ignore-unused ./PycharmProjects/myproject/ > ~/static_analysis.txt
WARNING : Line 9: Could not import module 'myproject.Utils.AdaptedConfigParser.Configs_parser'
I tried to get around it by adding a .pth file with the project root to the lib/python2.7/site-packages
Now when I call python with that virtual environment activated from anywhere, I can do the following:
$ python
Python 2.7.6rc1 (default, Jan 19 2014, 18:57:40)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import myproject.Utils.AdaptedConfigParser.Configs_parser
>>>
And it works just fine.
However, when snakefood is launched with that virtual environement, it still returns the same error.
$ sfood --internal --follow --ignore-unused ./PycharmProjects/myproject/ > ~/static_analysis.txt
WARNING : Line 9: Could not import module 'myproject.Utils.AdaptedConfigParser.Configs_parser'
At this point I don't even understand where the problem with imports could come from.
In addition to that, when --internal flag is taken away, it fails imports even of the python builtin module, which doesn't make any sense to me:
WARNING : Line 80: Could not import module 'builtins'
WARNING : Line 190: Could not import module 'pyamg'
Have anyone encountered such a problem previously? If yes, is there a way of getting around it?
I had similar issues, turns out the warning in my case was generated because of __all__ declarations.
e.g.
__all__ = ['abc',
'aaa',
...
]
Above code gives out the warnings:
WARNING : Line xx: Could not import module 'abc'
WARNING : Line xx: Could not import module 'aaa'
I modified the warning constant ERROR_IMPORT within snakefood\lib\python\find.py to add the name of the file where the error occurs along with the line number and module name. That way you can target the specific file and line number pretty much figure out the problem.
Hope this helps!

pylint complains on py.test: "Module 'pytest' has no 'raises' member"

With the following code:
import pytest
def test_a():
with pytest.raises(Exception):
1/0
If I run pylint on it, it will make a complain that "raises" is not a member of module pytest:
E: 3,9:test_a: Module 'pytest' has no 'raises' member
Which is obviously not true. Any idea why pylint is making such a mistake? Is this a known bug?
py.test version:
> py.test --version
This is py.test version 2.2.3, imported from C:\Python27\lib\site-packages\pytest.pyc
PyLint version:
> pylint --version
No config file found, using default configuration
pylint 0.25.1,
astng 0.23.1, common 0.57.1
Python 2.7.2 (default, Jun 24 2011, 12:22:14) [MSC v.1500 64 bit (AMD64)]
You can silence this in a pylintrc file with:
ignored-classes=pytest
Last time I looked pylib does some heavy dynamic in low level python stuff, such as completely redefining the import code. It is very likely that this completely baffles pylint/astng, and prevents it from getting what is inside the pytest module: pylint/astng does not import the code it analyzes, it parses it, meaning that stuff which is dynamically initialized at import time will usually go unnoticed, which in turn generates false positives such as the one you report.
From there, you face the following choices:
use another unittest framework, less dynamic than py.test
silence the warnings / errors on your test code manually
use another linter which is happier than pylint on py.test (I'm interested to know how pychecker / pyflakes fare on that code)
write the astng plugin which will help astng grok the pylib tricks and submit it as a patch to the astng maintainers (and get extra credit from that)

Categories