How to use collections.abc from both Python 3.8+ and Python 2.7 [duplicate]
This question already has an answer here:
Python 2 and Python 3 dual development
6 answers
In Python 3.3 "abstract base classes" in collections
(like MutableMapping
or MutableSequence
) were moved to second-level module collections.abc
. So in Python 3.3+ the real type is collections.abc.MutableMapping
and so on. Documentation states that the old alias names (e.g. collections.MutableMapping
) will be available up to Python 3.7 (currently the latest version), however in 3.8 these aliases will be removed.
Current version of Python 3.7 even produces a warning when you use the alias names:
./scripts/generateBoard.py:145: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
elif isinstance(value, (collections.MutableMapping, collections.MutableSequence)) == True:
In python 2.7 there is no collections.abc
.
How can Python script handle this difference in the most convenient way, when it is meant to be used with (almost) any Python version? I'm looking for a solution which would ideally solve this mess in one central place, without having to use try: ... except: ...
all over the script everywhere I need this type?
python python-3.x python-2.7
marked as duplicate by jonrsharpe
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 30 '18 at 14:57
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Python 2 and Python 3 dual development
6 answers
In Python 3.3 "abstract base classes" in collections
(like MutableMapping
or MutableSequence
) were moved to second-level module collections.abc
. So in Python 3.3+ the real type is collections.abc.MutableMapping
and so on. Documentation states that the old alias names (e.g. collections.MutableMapping
) will be available up to Python 3.7 (currently the latest version), however in 3.8 these aliases will be removed.
Current version of Python 3.7 even produces a warning when you use the alias names:
./scripts/generateBoard.py:145: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
elif isinstance(value, (collections.MutableMapping, collections.MutableSequence)) == True:
In python 2.7 there is no collections.abc
.
How can Python script handle this difference in the most convenient way, when it is meant to be used with (almost) any Python version? I'm looking for a solution which would ideally solve this mess in one central place, without having to use try: ... except: ...
all over the script everywhere I need this type?
python python-3.x python-2.7
marked as duplicate by jonrsharpe
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 30 '18 at 14:57
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Python 2 and Python 3 dual development
6 answers
In Python 3.3 "abstract base classes" in collections
(like MutableMapping
or MutableSequence
) were moved to second-level module collections.abc
. So in Python 3.3+ the real type is collections.abc.MutableMapping
and so on. Documentation states that the old alias names (e.g. collections.MutableMapping
) will be available up to Python 3.7 (currently the latest version), however in 3.8 these aliases will be removed.
Current version of Python 3.7 even produces a warning when you use the alias names:
./scripts/generateBoard.py:145: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
elif isinstance(value, (collections.MutableMapping, collections.MutableSequence)) == True:
In python 2.7 there is no collections.abc
.
How can Python script handle this difference in the most convenient way, when it is meant to be used with (almost) any Python version? I'm looking for a solution which would ideally solve this mess in one central place, without having to use try: ... except: ...
all over the script everywhere I need this type?
python python-3.x python-2.7
This question already has an answer here:
Python 2 and Python 3 dual development
6 answers
In Python 3.3 "abstract base classes" in collections
(like MutableMapping
or MutableSequence
) were moved to second-level module collections.abc
. So in Python 3.3+ the real type is collections.abc.MutableMapping
and so on. Documentation states that the old alias names (e.g. collections.MutableMapping
) will be available up to Python 3.7 (currently the latest version), however in 3.8 these aliases will be removed.
Current version of Python 3.7 even produces a warning when you use the alias names:
./scripts/generateBoard.py:145: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
elif isinstance(value, (collections.MutableMapping, collections.MutableSequence)) == True:
In python 2.7 there is no collections.abc
.
How can Python script handle this difference in the most convenient way, when it is meant to be used with (almost) any Python version? I'm looking for a solution which would ideally solve this mess in one central place, without having to use try: ... except: ...
all over the script everywhere I need this type?
This question already has an answer here:
Python 2 and Python 3 dual development
6 answers
python python-3.x python-2.7
python python-3.x python-2.7
edited Dec 30 '18 at 16:18
JJJ
29.1k147591
29.1k147591
asked Dec 30 '18 at 14:42
Freddie ChopinFreddie Chopin
4,7451439
4,7451439
marked as duplicate by jonrsharpe
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 30 '18 at 14:57
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by jonrsharpe
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 30 '18 at 14:57
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Place this at the top of the script:
import collections
try:
collectionsAbc = collections.abc
except AttributeError:
collectionsAbc = collections
Then change all prefixes of the abstract base types, e.g. change collections.abc.MutableMapping
or collections.MutableMapping
to collectionsAbc.MutableMapping
.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Place this at the top of the script:
import collections
try:
collectionsAbc = collections.abc
except AttributeError:
collectionsAbc = collections
Then change all prefixes of the abstract base types, e.g. change collections.abc.MutableMapping
or collections.MutableMapping
to collectionsAbc.MutableMapping
.
add a comment |
Place this at the top of the script:
import collections
try:
collectionsAbc = collections.abc
except AttributeError:
collectionsAbc = collections
Then change all prefixes of the abstract base types, e.g. change collections.abc.MutableMapping
or collections.MutableMapping
to collectionsAbc.MutableMapping
.
add a comment |
Place this at the top of the script:
import collections
try:
collectionsAbc = collections.abc
except AttributeError:
collectionsAbc = collections
Then change all prefixes of the abstract base types, e.g. change collections.abc.MutableMapping
or collections.MutableMapping
to collectionsAbc.MutableMapping
.
Place this at the top of the script:
import collections
try:
collectionsAbc = collections.abc
except AttributeError:
collectionsAbc = collections
Then change all prefixes of the abstract base types, e.g. change collections.abc.MutableMapping
or collections.MutableMapping
to collectionsAbc.MutableMapping
.
answered Dec 30 '18 at 14:42
Freddie ChopinFreddie Chopin
4,7451439
4,7451439
add a comment |
add a comment |