From d7281aac6fb98dc4ba2418e5e46711223715e52a Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Mon, 20 Sep 2021 20:34:22 +0200 Subject: [PATCH 1/2] from __future__ import: not needed in Python 3 --- sklearn/impute/tests/test_impute.py | 2 -- sklearn/neighbors/_nca.py | 2 -- 2 files changed, 4 deletions(-) diff --git a/sklearn/impute/tests/test_impute.py b/sklearn/impute/tests/test_impute.py index 5248d4207cbf3..2534f94116b57 100644 --- a/sklearn/impute/tests/test_impute.py +++ b/sklearn/impute/tests/test_impute.py @@ -1,5 +1,3 @@ -from __future__ import division - import pytest import numpy as np diff --git a/sklearn/neighbors/_nca.py b/sklearn/neighbors/_nca.py index 4436587667001..74ddb58f1d07a 100644 --- a/sklearn/neighbors/_nca.py +++ b/sklearn/neighbors/_nca.py @@ -7,8 +7,6 @@ # John Chiotellis # License: BSD 3 clause -from __future__ import print_function - from warnings import warn import numpy as np import sys From 5db96e836c00062a572c4ed11037416a278a24ff Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Mon, 20 Sep 2021 20:39:59 +0200 Subject: [PATCH 2/2] PEP 562 backport not needed anymore (Python >= 3.7) --- sklearn/externals/_pep562.py | 58 ---------------------- sklearn/tests/test_docstring_parameters.py | 7 --- 2 files changed, 65 deletions(-) delete mode 100644 sklearn/externals/_pep562.py diff --git a/sklearn/externals/_pep562.py b/sklearn/externals/_pep562.py deleted file mode 100644 index 86d374960b49f..0000000000000 --- a/sklearn/externals/_pep562.py +++ /dev/null @@ -1,58 +0,0 @@ -""" -Backport of PEP 562. - -https://pypi.org/search/?q=pep562 - -Licensed under MIT -Copyright (c) 2018 Isaac Muse - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the Software without restriction, including without limitation -the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, -and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF -CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -IN THE SOFTWARE. -""" -from __future__ import unicode_literals -import sys - -__all__ = ('Pep562',) - - -class Pep562(object): - """ - Backport of PEP 562 . - - Wraps the module in a class that exposes the mechanics to override `__dir__` and `__getattr__`. - The given module will be searched for overrides of `__dir__` and `__getattr__` and use them when needed. - """ - - def __init__(self, name): - """Acquire `__getattr__` and `__dir__`, but only replace module for versions less than Python 3.7.""" - - self._module = sys.modules[name] - self._get_attr = getattr(self._module, '__getattr__', None) - self._get_dir = getattr(self._module, '__dir__', None) - sys.modules[name] = self - - def __dir__(self): - """Return the overridden `dir` if one was provided, else apply `dir` to the module.""" - - return self._get_dir() if self._get_dir else dir(self._module) - - def __getattr__(self, name): - """Attempt to retrieve the attribute from the module, and if missing, use the overridden function if present.""" - - try: - return getattr(self._module, name) - except AttributeError: - if self._get_attr: - return self._get_attr(name) - raise diff --git a/sklearn/tests/test_docstring_parameters.py b/sklearn/tests/test_docstring_parameters.py index 8f6326f62e4aa..de1ac9b1c04dd 100644 --- a/sklearn/tests/test_docstring_parameters.py +++ b/sklearn/tests/test_docstring_parameters.py @@ -21,7 +21,6 @@ from sklearn.utils.estimator_checks import _enforce_estimator_tags_x from sklearn.utils.estimator_checks import _construct_instance from sklearn.utils.deprecation import _is_deprecated -from sklearn.externals._pep562 import Pep562 from sklearn.datasets import make_classification from sklearn.linear_model import LogisticRegression from sklearn.preprocessing import FunctionTransformer @@ -162,12 +161,6 @@ def test_tabs(): # because we don't import mod = importlib.import_module(modname) - # TODO: Remove when minimum python version is 3.7 - # unwrap to get module because Pep562 backport wraps the original - # module - if isinstance(mod, Pep562): - mod = mod._module - try: source = inspect.getsource(mod) except IOError: # user probably should have run "make clean"