Skip to content

Commit

Permalink
Fix for Python 4
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Jan 9, 2020
1 parent 0c98567 commit 93a9945
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 32 deletions.
18 changes: 9 additions & 9 deletions src/wrapt/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,8 @@
import sys

PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3

if PY3:
string_types = str,

import builtins
exec_ = getattr(builtins, "exec")
del builtins

else:
if PY2:
string_types = basestring,

def exec_(_code_, _globs_=None, _locs_=None):
Expand All @@ -30,6 +22,14 @@ def exec_(_code_, _globs_=None, _locs_=None):
_locs_ = _globs_
exec("""exec _code_ in _globs_, _locs_""")

else:
string_types = str,

import builtins

exec_ = getattr(builtins, "exec")
del builtins

from functools import partial
from inspect import ismethod, isclass, formatargspec
from collections import namedtuple
Expand Down
34 changes: 17 additions & 17 deletions src/wrapt/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
import threading

PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3

if PY3:
if PY2:
string_types = basestring,
else:
import importlib
string_types = str,
else:
string_types = basestring,

from .decorators import synchronized

Expand Down Expand Up @@ -188,7 +187,20 @@ def find_module(self, fullname, path=None):
# Now call back into the import system again.

try:
if PY3:
if PY2:
# For Python 2 we don't have much choice but to
# call back in to __import__(). This will
# actually cause the module to be imported. If no
# module could be found then ImportError will be
# raised. Otherwise we return a loader which
# returns the already loaded module and invokes
# the post import hooks.

__import__(fullname)

return _ImportHookLoader()

else:
# For Python 3 we need to use find_spec().loader
# from the importlib.util module. It doesn't actually
# import the target module and only finds the
Expand All @@ -204,18 +216,6 @@ def find_module(self, fullname, path=None):
if loader:
return _ImportHookChainedLoader(loader)

else:
# For Python 2 we don't have much choice but to
# call back in to __import__(). This will
# actually cause the module to be imported. If no
# module could be found then ImportError will be
# raised. Otherwise we return a loader which
# returns the already loaded module and invokes
# the post import hooks.

__import__(fullname)

return _ImportHookLoader()

finally:
del self.in_progress[fullname]
Expand Down
11 changes: 5 additions & 6 deletions src/wrapt/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
import inspect

PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3

if PY3:
string_types = str,
else:
if PY2:
string_types = basestring,
else:
string_types = str,

def with_metaclass(meta, *bases):
"""Create a base class with a metaclass."""
Expand Down Expand Up @@ -117,7 +116,7 @@ def __dir__(self):
def __str__(self):
return str(self.__wrapped__)

if PY3:
if not PY2:
def __bytes__(self):
return bytes(self.__wrapped__)

Expand All @@ -130,7 +129,7 @@ def __repr__(self):
def __reversed__(self):
return reversed(self.__wrapped__)

if PY3:
if not PY2:
def __round__(self):
return round(self.__wrapped__)

Expand Down

0 comments on commit 93a9945

Please sign in to comment.