Skip to content

Commit

Permalink
Fix several warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
altendky committed Nov 19, 2018
1 parent 1b41b35 commit 02fdb32
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 27 deletions.
8 changes: 6 additions & 2 deletions src/future/backports/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import subprocess
from math import ceil as oldceil
from collections import Mapping, MutableMapping

from operator import itemgetter as _itemgetter, eq as _eq
import sys
Expand All @@ -25,7 +24,12 @@
from itertools import repeat as _repeat, chain as _chain, starmap as _starmap
from socket import getaddrinfo, SOCK_STREAM, error, socket

from future.utils import iteritems, itervalues, PY26, PY3
from future.utils import iteritems, itervalues, PY2, PY26, PY3

if PY2:
from collections import Mapping, MutableMapping
else:
from collections.abc import Mapping, MutableMapping


def ceil(x):
Expand Down
10 changes: 8 additions & 2 deletions src/future/backports/urllib/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,17 @@
import socket
import sys
import time
import collections
import tempfile
import contextlib
import warnings

from future.utils import PY2

if PY2:
from collections import Iterable
else:
from collections.abc import Iterable

# check for SSL
try:
import ssl
Expand Down Expand Up @@ -1221,7 +1227,7 @@ def do_request_(self, request):
mv = memoryview(data)
size = len(mv) * mv.itemsize
except TypeError:
if isinstance(data, collections.Iterable):
if isinstance(data, Iterable):
raise ValueError("Content-Length should be specified "
"for iterable data of type %r %r" % (type(data),
data))
Expand Down
10 changes: 7 additions & 3 deletions src/past/builtins/misc.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from __future__ import unicode_literals
import sys
import inspect
from collections import Mapping

from future.utils import PY3, exec_
from future.utils import PY2, PY3, exec_

if PY2:
from collections import Mapping
else:
from collections.abc import Mapping


if PY3:
Expand Down Expand Up @@ -76,7 +80,7 @@ def execfile(filename, myglobals=None, mylocals=None):
raise TypeError('globals must be a mapping')
if not isinstance(mylocals, Mapping):
raise TypeError('locals must be a mapping')
with open(filename, "rbU") as fin:
with open(filename, "rb") as fin:
source = fin.read()
code = compile(source, filename, "exec")
exec_(code, myglobals, mylocals)
Expand Down
6 changes: 5 additions & 1 deletion src/past/types/oldstr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
Pure-Python implementation of a Python 2-like str object for Python 3.
"""

from collections import Iterable
from numbers import Integral

from past.utils import PY2, with_metaclass

if PY2:
from collections import Iterable
else:
from collections.abc import Iterable


_builtin_bytes = bytes

Expand Down
8 changes: 6 additions & 2 deletions tests/test_future/test_backports.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@
import inspect
import pickle
from random import randrange, shuffle
from collections import Mapping, MutableMapping

from future.backports.misc import (count,
_count,
OrderedDict,
Counter,
ChainMap,
_count_elements)
from future.utils import PY26
from future.utils import PY2, PY26
from future.tests.base import unittest, skip26, expectedFailurePY27

if PY2:
from collections import Mapping, MutableMapping
else:
from collections.abc import Mapping, MutableMapping


class CountTest(unittest.TestCase):
"""Test the count function."""
Expand Down
7 changes: 5 additions & 2 deletions tests/test_future/test_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,12 +701,15 @@ def test_multiple_inheritance(self):
"""
Issue #96 (for newbytes instead of newobject)
"""
import collections
if utils.PY2:
from collections import Container
else:
from collections.abc import Container

class Base(bytes):
pass

class Foo(Base, collections.Container):
class Foo(Base, Container):
def __contains__(self, item):
return False

Expand Down
7 changes: 5 additions & 2 deletions tests/test_future/test_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,15 @@ def test_multiple_inheritance(self):
"""
Issue #96 (for newdict instead of newobject)
"""
import collections
if utils.PY2:
from collections import Container
else:
from collections.abc import Container

class Base(dict):
pass

class Foo(Base, collections.Container):
class Foo(Base, Container):
def __contains__(self, item):
return False

Expand Down
6 changes: 3 additions & 3 deletions tests/test_future/test_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def __int__(self):

class Foo3(int):
def __int__(self):
return self
return self.real

class Foo4(int):
def __int__(self):
Expand Down Expand Up @@ -1069,12 +1069,12 @@ def test_multiple_inheritance(self):
"""
Issue #96 (for newint instead of newobject)
"""
import collections
import collections.abc

class Base(int):
pass

class Foo(Base, collections.Container):
class Foo(Base, collections.abc.Container):
def __add__(self, other):
return 0

Expand Down
7 changes: 5 additions & 2 deletions tests/test_future/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,15 @@ def test_multiple_inheritance(self):
"""
Issue #96 (for newdict instead of newobject)
"""
import collections
if utils.PY2:
from collections import Container
else:
from collections.abc import Container

class Base(list):
pass

class Foo(Base, collections.Container):
class Foo(Base, Container):
def __contains__(self, item):
return False

Expand Down
7 changes: 5 additions & 2 deletions tests/test_future/test_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,15 @@ def test_multiple_inheritance(self):
"""
Issue #96
"""
import collections
if utils.PY2:
from collections import Container
else:
from collections.abc import Container

class Base(object):
pass

class Foo(Base, collections.Container):
class Foo(Base, Container):
def __contains__(self, item):
return False

Expand Down
10 changes: 8 additions & 2 deletions tests/test_future/test_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
from future.builtins import range
from future.tests.base import unittest

from collections import Iterator, Sequence
from operator import attrgetter

from future.utils import PY2

if PY2:
from collections import Iterator, Sequence
else:
from collections.abc import Iterator, Sequence


class RangeTests(unittest.TestCase):
def test_range(self):
Expand Down Expand Up @@ -192,7 +198,7 @@ def test_rev_stepped_slice_rev_stepped_range(self):

def test_slice_zero_step(self):
msg = '^slice step cannot be zero$'
with self.assertRaisesRegexp(ValueError, msg):
with self.assertRaisesRegex(ValueError, msg):
range(8)[::0]

def test_properties(self):
Expand Down
7 changes: 5 additions & 2 deletions tests/test_future/test_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,15 @@ def test_multiple_inheritance(self):
"""
Issue #96 (for newstr instead of newobject)
"""
import collections
if utils.PY2:
from collections import Container
else:
from collections.abc import Container

class Base(str):
pass

class Foo(Base, collections.Container):
class Foo(Base, Container):
def __contains__(self, item):
return False

Expand Down
4 changes: 2 additions & 2 deletions tests/test_future/test_urllib_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from future.tests.base import unittest


class TestFile(object):
class File(object):

def __init__(self):
self.closed = False
Expand All @@ -28,7 +28,7 @@ class Testaddbase(unittest.TestCase):
# TODO(jhylton): Write tests for other functionality of addbase()

def setUp(self):
self.fp = TestFile()
self.fp = File()
self.addbase = urllib_response.addbase(self.fp)

def test_with(self):
Expand Down

0 comments on commit 02fdb32

Please sign in to comment.