I am getting the following warning:
DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
return isinstance(x, collections.Callable)
when I run my unit tests for my project. I replaced:
from abc import ABC, abstractmethod
with:
from collections.abc import Callable
from abc import abstractmethod
and am still getting the same warning. Is there somewhere else I should be importing abstractmethod from?
I had the same issue with pytest. Check the warning message once again and make sure it is an issue with your imports. In my Python 3.7 environment it was some dependency package called pyreadlines that caused the error:
======== warnings summary ===============
C:\Users\Me\anaconda3\envs\myenv\lib\site-packages\pyreadline\py3k_compat.py:8
C:\Users\Me\anaconda3\envs\myenv\lib\site-packages\pyreadline\py3k_compat.py:8: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working
return isinstance(x, collections.Callable)
-- Docs: https://docs.pytest.org/en/stable/warnings.html
Unfortunately pyreadline was already "up-to-date" and only supports Python up to 3.5 so there's no need to blame the maintainers.
Replacing the import statement in that file as you described in you post fixed the issue for me.
Related
I have a python package with a large number of subpackages and I've recently rewritten a good chunk of it and renamed and reorganized the packages and objects.
For example, in the past, I would import something like
from package import MyClass
but now, it should be
from package.subpackage import MyClass
For backwards compatibility, I've created symbols in the old locations that import and use the modules and objects from the new namespaces.
In /package/__init__.py
from .subpackage import MyClass
Is there a way to raise a deprecation warning when someone tries to import or access one of the old namespace locations? With a class I could use __getattr__. Is there a similar mechanism for catching attribute access on modules and packages?
Whenever I try to just import winappdbg it gives me an error ModuleNotFoundError: No module named 'breakpoint'. So, I tried installing breakpoint and that gives me another error ModuleNotFoundError: No module named 'ConfigParser' and I've installed configparser several times and still get the error. (Can't find capital ConfigParser) I'm using Windows 10/PyCharm Community Edition 2017.2.3/python 3.6.3
WinAppDbg is only for Python 2.x, it does not work on Python 3.x. Honestly, I had no idea it would even let you import it.
All those import errors are happening not because of missing dependencies (also, no idea there were similarly named modules in pip), they are submodules of WinAppDbg itself. Since Python 3 has a different syntax to specify those, it tries to load them as external modules instead. I suppose you could fix that in the sources by prepending a dot before every submodule import, but I'm guessing more stuff would break down the road (string handling for example is radically different and that would affect the ctypes layer).
TL;DR: use Python 2.x.
I am running some very simple unit tests in Python, and found that the assertTrue() function won't work, while in the same testcase the assertEqual() is working fine.
To simplify the issue, I have minimized the code into the following:
import unittest
class easyTest (unittest.TestCase):
def setUp(self):
pass
def test_true(self):
self.assertTrue(True)
if __name__ == "__main__":
unittest.main()
This batch of codes runs perfectly on my Windows laptop, but returns
AttributeError: easyTest instance has no attribute 'assertTrue'
when I try to run it on Linux.
On both laptops, I am using python 2.7.6, on IDE pyCharm Community Edition 2017.1.4. My Linux laptop is running Ubuntu 14.04.1
I have found a very similar question here:
AttributeError: TestSwitch instance has no attribute 'assertTrue'
And since it seems that nobody is answering the question, I am asking here again, hoping for some prominent answers.
According to your comment, the unittest version you are using is (the long deprecated) stand-alone PyUnit 1.4.1 package. As the package's homepage mentions:
Unless you're stuck in the year 2000, PyUnit is in your Python standard library as module unittest.
And indeed, unittest was added to the stdlib in Python 2.1.
IOW, unless you're stuck with an antediluvian legacy code base (using Python < 2.1 !), you should just uninstall PyUnit and your problem will be solved.
Is it possible that you have a second unittest module or package in your python path?
If you created a unittest.py file or a unittest directory containing an __init__.py file, python could find that before it finds the normal module in the standard python library.
Naming a local module or package unittest is the equivalent of naming a local variable list or dict or map; you are masking the built-in name with a local redefinition.
Rename that module or package to something else to fix this.
How do I determine which version of the python module 'time' is installed. For other modules .version.version or .__version__ work, however for time, both these methods return the error 'module' object has no attribute 'version' or 'version'
Module time is built-in in the Python interpreter. No other version than the interpreter's itself can be a valid answer (you can access that one using sys.version).
Other built-in modules like os, sys etc. also do not have their own version information.
I'm currently getting the warning every time I run a Python script that uses MySQLdb:
/var/lib/python-support/python2.6/MySQLdb/__init__.py:34:
DeprecationWarning: the sets module is deprecated
from sets import ImmutableSet
I'd rather not mess with their lib if possible. I'm on Ubuntu server. Anyone know an easy way to fix that warning message?
Thanks
UPDATE:
Fixed it based on the suggestions below and this link: https://bugzilla.redhat.com/show_bug.cgi?id=505611
import warnings
warnings.filterwarnings('ignore', '.*the sets module is deprecated.*',
DeprecationWarning, 'MySQLdb')
import MySQLdb
Do this before the mysql module is imported
import warnings
warnings.filterwarnings(action="ignore", message='the sets module is deprecated')
import sets
You can ignore the warning using the warnings module, or the -W argument to Python. Don't ignore all DeprecationWarnings, though, just the ones from MySQLdb :)
All it means is the sets module (more specifically the immutableset part) is deprecated, and you should use it's replacement, set. Set is inbuilt so no need to import.
If you need an immutable set, frozenset() should work.