summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCeridwen <ceridwenv@gmail.com>2016-05-16 18:56:21 -0400
committerCeridwen <ceridwenv@gmail.com>2016-05-17 10:45:31 -0400
commite16db7fc2d007c2310c5db8e61057c94624a6d8f (patch)
tree682f0f2e1cddf63488cc047233495102fa62e96c
parentc6563e8664fa0c94496907ad64f6f6c07ee0b63a (diff)
downloadastroid-git-e16db7fc2d007c2310c5db8e61057c94624a6d8f.tar.gz
Convert all files to new license header
-rw-r--r--astroid/__init__.py20
-rw-r--r--astroid/__pkginfo__.py20
-rw-r--r--astroid/as_string.py20
-rw-r--r--astroid/brain/brain_builtin_inference.py3
-rw-r--r--astroid/brain/brain_dateutil.py33
-rw-r--r--astroid/brain/brain_functools.py3
-rw-r--r--astroid/brain/brain_gi.py3
-rw-r--r--astroid/brain/brain_mechanize.py3
-rw-r--r--astroid/brain/brain_nose.py20
-rw-r--r--astroid/brain/brain_numpy.py19
-rw-r--r--astroid/brain/brain_pkg_resources.py19
-rw-r--r--astroid/brain/brain_pytest.py65
-rw-r--r--astroid/brain/brain_qt.py3
-rw-r--r--astroid/brain/brain_six.py19
-rw-r--r--astroid/brain/brain_ssl.py3
-rw-r--r--astroid/brain/brain_stdlib.py3
-rw-r--r--astroid/builder.py20
-rw-r--r--astroid/context.py20
-rw-r--r--astroid/decorators.py20
-rw-r--r--astroid/exceptions.py20
-rw-r--r--astroid/inference.py20
-rw-r--r--astroid/interpreter/__init__.py3
-rw-r--r--astroid/interpreter/assign.py20
-rw-r--r--astroid/interpreter/lookup.py20
-rw-r--r--astroid/interpreter/objectmodel.py20
-rw-r--r--astroid/interpreter/objects.py20
-rw-r--r--astroid/interpreter/runtimeabc.py20
-rw-r--r--astroid/interpreter/scope.py223
-rw-r--r--astroid/interpreter/util.py20
-rw-r--r--astroid/manager.py20
-rw-r--r--astroid/modutils.py20
-rw-r--r--astroid/nodes.py20
-rw-r--r--astroid/protocols.py20
-rw-r--r--astroid/raw_building.py20
-rw-r--r--astroid/test_utils.py3
-rw-r--r--astroid/tests/__init__.py3
-rw-r--r--astroid/tests/resources.py20
-rw-r--r--astroid/tests/unittest_brain.py19
-rw-r--r--astroid/tests/unittest_builder.py20
-rw-r--r--astroid/tests/unittest_helpers.py20
-rw-r--r--astroid/tests/unittest_inference.py20
-rw-r--r--astroid/tests/unittest_lookup.py20
-rw-r--r--astroid/tests/unittest_manager.py20
-rw-r--r--astroid/tests/unittest_modutils.py20
-rw-r--r--astroid/tests/unittest_nodes.py20
-rw-r--r--astroid/tests/unittest_object_model.py20
-rw-r--r--astroid/tests/unittest_objects.py1146
-rw-r--r--astroid/tests/unittest_protocols.py20
-rw-r--r--astroid/tests/unittest_python3.py20
-rw-r--r--astroid/tests/unittest_raw_building.py3
-rw-r--r--astroid/tests/unittest_regrtest.py20
-rw-r--r--astroid/tests/unittest_scoped_nodes.py20
-rw-r--r--astroid/tests/unittest_transforms.py476
-rw-r--r--astroid/tests/unittest_utils.py20
-rw-r--r--astroid/transforms.py20
-rw-r--r--astroid/tree/__init__.py3
-rw-r--r--astroid/tree/base.py20
-rw-r--r--astroid/tree/node_classes.py20
-rw-r--r--astroid/tree/rebuilder.py20
-rw-r--r--astroid/tree/scoped_nodes.py20
-rw-r--r--astroid/tree/treeabc.py20
-rw-r--r--astroid/util.py20
62 files changed, 1121 insertions, 1754 deletions
diff --git a/astroid/__init__.py b/astroid/__init__.py
index 6afecf25..72f2c78a 100644
--- a/astroid/__init__.py
+++ b/astroid/__init__.py
@@ -1,20 +1,6 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""Python Abstract Syntax Tree New Generation
The aim of this module is to provide a common base representation of
diff --git a/astroid/__pkginfo__.py b/astroid/__pkginfo__.py
index ee4712d7..df41ce7d 100644
--- a/astroid/__pkginfo__.py
+++ b/astroid/__pkginfo__.py
@@ -1,20 +1,6 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""astroid packaging information"""
import sys
diff --git a/astroid/as_string.py b/astroid/as_string.py
index 800617e7..652720a7 100644
--- a/astroid/as_string.py
+++ b/astroid/as_string.py
@@ -1,20 +1,6 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""This module renders Astroid nodes as string:
* :func:`to_code` function return equivalent (hopefuly valid) python string
diff --git a/astroid/brain/brain_builtin_inference.py b/astroid/brain/brain_builtin_inference.py
index ef0866c5..96acbd39 100644
--- a/astroid/brain/brain_builtin_inference.py
+++ b/astroid/brain/brain_builtin_inference.py
@@ -1,3 +1,6 @@
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""Astroid hooks for various builtins."""
import collections
diff --git a/astroid/brain/brain_dateutil.py b/astroid/brain/brain_dateutil.py
index 0b45412c..2c385ecc 100644
--- a/astroid/brain/brain_dateutil.py
+++ b/astroid/brain/brain_dateutil.py
@@ -1,15 +1,18 @@
-"""Astroid hooks for dateutil"""
-
-import textwrap
-
-from astroid import MANAGER, register_module_extender
-from astroid.builder import AstroidBuilder
-
-def dateutil_transform():
- return AstroidBuilder(MANAGER).string_build(textwrap.dedent('''
- import datetime
- def parse(timestr, parserinfo=None, **kwargs):
- return datetime.datetime()
- '''))
-
-register_module_extender(MANAGER, 'dateutil.parser', dateutil_transform)
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
+"""Astroid hooks for dateutil"""
+
+import textwrap
+
+from astroid import MANAGER, register_module_extender
+from astroid.builder import AstroidBuilder
+
+def dateutil_transform():
+ return AstroidBuilder(MANAGER).string_build(textwrap.dedent('''
+ import datetime
+ def parse(timestr, parserinfo=None, **kwargs):
+ return datetime.datetime()
+ '''))
+
+register_module_extender(MANAGER, 'dateutil.parser', dateutil_transform)
diff --git a/astroid/brain/brain_functools.py b/astroid/brain/brain_functools.py
index 7fff071b..b80ec1ca 100644
--- a/astroid/brain/brain_functools.py
+++ b/astroid/brain/brain_functools.py
@@ -1,3 +1,6 @@
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""Astroid hooks for understanding functools library module."""
import astroid
diff --git a/astroid/brain/brain_gi.py b/astroid/brain/brain_gi.py
index 62b013c3..0e423307 100644
--- a/astroid/brain/brain_gi.py
+++ b/astroid/brain/brain_gi.py
@@ -1,3 +1,6 @@
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""Astroid hooks for the Python 2 GObject introspection bindings.
Helps with understanding everything imported from 'gi.repository'
diff --git a/astroid/brain/brain_mechanize.py b/astroid/brain/brain_mechanize.py
index 20a253a4..2026d3cd 100644
--- a/astroid/brain/brain_mechanize.py
+++ b/astroid/brain/brain_mechanize.py
@@ -1,3 +1,6 @@
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
from astroid import MANAGER, register_module_extender
from astroid.builder import AstroidBuilder
diff --git a/astroid/brain/brain_nose.py b/astroid/brain/brain_nose.py
index 80d6563d..b9adb220 100644
--- a/astroid/brain/brain_nose.py
+++ b/astroid/brain/brain_nose.py
@@ -1,20 +1,6 @@
-# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""Hooks for nose library."""
diff --git a/astroid/brain/brain_numpy.py b/astroid/brain/brain_numpy.py
index 25647ee9..493a0dcf 100644
--- a/astroid/brain/brain_numpy.py
+++ b/astroid/brain/brain_numpy.py
@@ -1,20 +1,5 @@
-# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it under
-# the terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option) any
-# later version.
-#
-# astroid is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
"""Astroid hooks for numpy."""
diff --git a/astroid/brain/brain_pkg_resources.py b/astroid/brain/brain_pkg_resources.py
index 7777fb71..dbbc8885 100644
--- a/astroid/brain/brain_pkg_resources.py
+++ b/astroid/brain/brain_pkg_resources.py
@@ -1,20 +1,5 @@
-# copyright 2003-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it under
-# the terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option) any
-# later version.
-#
-# astroid is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
import astroid
from astroid import parse
diff --git a/astroid/brain/brain_pytest.py b/astroid/brain/brain_pytest.py
index 4f615c14..f20605f0 100644
--- a/astroid/brain/brain_pytest.py
+++ b/astroid/brain/brain_pytest.py
@@ -1,31 +1,34 @@
-"""Astroid hooks for pytest."""
-from __future__ import absolute_import
-from astroid import MANAGER, register_module_extender
-from astroid.builder import AstroidBuilder
-
-
-def pytest_transform():
- return AstroidBuilder(MANAGER).string_build('''
-
-try:
- import _pytest.mark
- import _pytest.recwarn
- import _pytest.runner
- import _pytest.python
-except ImportError:
- pass
-else:
- deprecated_call = _pytest.recwarn.deprecated_call
- exit = _pytest.runner.exit
- fail = _pytest.runner.fail
- fixture = _pytest.python.fixture
- importorskip = _pytest.runner.importorskip
- mark = _pytest.mark.MarkGenerator()
- raises = _pytest.python.raises
- skip = _pytest.runner.skip
- yield_fixture = _pytest.python.yield_fixture
-
-''')
-
-register_module_extender(MANAGER, 'pytest', pytest_transform)
-register_module_extender(MANAGER, 'py.test', pytest_transform)
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
+"""Astroid hooks for pytest."""
+from __future__ import absolute_import
+from astroid import MANAGER, register_module_extender
+from astroid.builder import AstroidBuilder
+
+
+def pytest_transform():
+ return AstroidBuilder(MANAGER).string_build('''
+
+try:
+ import _pytest.mark
+ import _pytest.recwarn
+ import _pytest.runner
+ import _pytest.python
+except ImportError:
+ pass
+else:
+ deprecated_call = _pytest.recwarn.deprecated_call
+ exit = _pytest.runner.exit
+ fail = _pytest.runner.fail
+ fixture = _pytest.python.fixture
+ importorskip = _pytest.runner.importorskip
+ mark = _pytest.mark.MarkGenerator()
+ raises = _pytest.python.raises
+ skip = _pytest.runner.skip
+ yield_fixture = _pytest.python.yield_fixture
+
+''')
+
+register_module_extender(MANAGER, 'pytest', pytest_transform)
+register_module_extender(MANAGER, 'py.test', pytest_transform)
diff --git a/astroid/brain/brain_qt.py b/astroid/brain/brain_qt.py
index f568b65f..30d8de75 100644
--- a/astroid/brain/brain_qt.py
+++ b/astroid/brain/brain_qt.py
@@ -1,3 +1,6 @@
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""Astroid hooks for the PyQT library."""
from astroid import MANAGER, register_module_extender
diff --git a/astroid/brain/brain_six.py b/astroid/brain/brain_six.py
index d2b0510f..21308078 100644
--- a/astroid/brain/brain_six.py
+++ b/astroid/brain/brain_six.py
@@ -1,20 +1,5 @@
-# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it under
-# the terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option) any
-# later version.
-#
-# astroid is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
"""Astroid hooks for six module."""
diff --git a/astroid/brain/brain_ssl.py b/astroid/brain/brain_ssl.py
index 1cf8d1b8..5f33d014 100644
--- a/astroid/brain/brain_ssl.py
+++ b/astroid/brain/brain_ssl.py
@@ -1,3 +1,6 @@
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""Astroid hooks for the ssl library."""
from astroid import MANAGER, register_module_extender
diff --git a/astroid/brain/brain_stdlib.py b/astroid/brain/brain_stdlib.py
index f3a6a716..33dfcd83 100644
--- a/astroid/brain/brain_stdlib.py
+++ b/astroid/brain/brain_stdlib.py
@@ -1,3 +1,6 @@
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""Astroid hooks for the Python standard library."""
# Namedtuple template strings
diff --git a/astroid/builder.py b/astroid/builder.py
index 0c05f8cf..bd941c53 100644
--- a/astroid/builder.py
+++ b/astroid/builder.py
@@ -1,20 +1,6 @@
-# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""The AstroidBuilder makes astroid from living object and / or from _ast
The builder is not thread safe and can't be used to parse different sources
diff --git a/astroid/context.py b/astroid/context.py
index 6497e7d8..95f1d9f5 100644
--- a/astroid/context.py
+++ b/astroid/context.py
@@ -1,20 +1,6 @@
-# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""Various context related utilities, including inference and call contexts."""
import contextlib
diff --git a/astroid/decorators.py b/astroid/decorators.py
index 826b7b25..20bb5b7d 100644
--- a/astroid/decorators.py
+++ b/astroid/decorators.py
@@ -1,20 +1,6 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
#
# The code in this file was originally part of logilab-common, licensed under
# the same license.
diff --git a/astroid/exceptions.py b/astroid/exceptions.py
index 21e9b61f..3e571006 100644
--- a/astroid/exceptions.py
+++ b/astroid/exceptions.py
@@ -1,20 +1,6 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""this module contains exceptions used in the astroid library
"""
from astroid import util
diff --git a/astroid/inference.py b/astroid/inference.py
index 48de4341..c32c3be1 100644
--- a/astroid/inference.py
+++ b/astroid/inference.py
@@ -1,20 +1,6 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""this module contains a set of functions to handle inference on astroid trees
"""
diff --git a/astroid/interpreter/__init__.py b/astroid/interpreter/__init__.py
index e69de29b..7a8e4fce 100644
--- a/astroid/interpreter/__init__.py
+++ b/astroid/interpreter/__init__.py
@@ -0,0 +1,3 @@
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
diff --git a/astroid/interpreter/assign.py b/astroid/interpreter/assign.py
index 4b9fb1e8..5b00afb8 100644
--- a/astroid/interpreter/assign.py
+++ b/astroid/interpreter/assign.py
@@ -1,20 +1,6 @@
-# copyright 2003-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
from astroid import exceptions
from astroid.interpreter import runtimeabc
diff --git a/astroid/interpreter/lookup.py b/astroid/interpreter/lookup.py
index 441d62f7..53f59b7d 100644
--- a/astroid/interpreter/lookup.py
+++ b/astroid/interpreter/lookup.py
@@ -1,20 +1,6 @@
-# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
import collections
diff --git a/astroid/interpreter/objectmodel.py b/astroid/interpreter/objectmodel.py
index 186be464..9ab06e4a 100644
--- a/astroid/interpreter/objectmodel.py
+++ b/astroid/interpreter/objectmodel.py
@@ -1,20 +1,6 @@
-# copyright 2003-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
#
# The code in this file was originally part of logilab-common, licensed under
# the same license.
diff --git a/astroid/interpreter/objects.py b/astroid/interpreter/objects.py
index a9196491..6b8b02e2 100644
--- a/astroid/interpreter/objects.py
+++ b/astroid/interpreter/objects.py
@@ -1,20 +1,6 @@
-# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""
Inference objects are a way to represent objects which are available
diff --git a/astroid/interpreter/runtimeabc.py b/astroid/interpreter/runtimeabc.py
index 8dec1089..04ea153f 100644
--- a/astroid/interpreter/runtimeabc.py
+++ b/astroid/interpreter/runtimeabc.py
@@ -1,20 +1,6 @@
-# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
import abc
diff --git a/astroid/interpreter/scope.py b/astroid/interpreter/scope.py
index 47fb3a0c..6314dcc7 100644
--- a/astroid/interpreter/scope.py
+++ b/astroid/interpreter/scope.py
@@ -1,119 +1,104 @@
-# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with astroid. If not, see <http://www.gnu.org/licenses/>.
-
-"""Implements logic for determing the scope of a node."""
-
-import itertools
-
-import six
-
-from astroid.tree import treeabc
-from astroid import util
-
-
-# import pdb; pdb.set_trace()
-
-@util.singledispatch
-def _scope_by_parent(parent, node):
- """Detect the scope of the *node* by parent's rules.
-
- The scope for certain kind of nodes depends on the
- parent, as it is the case for default values of arguments
- and function annotation, where the scope is not the scope of
- the parent, but the parent scope of the parent.
- """
- # This is separated in multiple dispatch methods on parents,
- # in order to decouple the implementation for the normal cases.
-
-
-def _node_arguments(node):
- for arg in itertools.chain(node.positional_and_keyword, node.keyword_only,
- (node.vararg, ), (node.kwarg, )):
- if arg and arg.annotation:
- yield arg
-
-
-@_scope_by_parent.register(treeabc.Arguments)
-def _scope_by_argument_parent(parent, node):
- args = parent
- for param in itertools.chain(args.positional_and_keyword, args.keyword_only):
- if param.default == node:
- return args.parent.parent.scope()
-
- if six.PY3 and node in _node_arguments(args):
- return args.parent.parent.scope()
-
-
-@_scope_by_parent.register(treeabc.FunctionDef)
-def _scope_by_function_parent(parent, node):
- # Verify if the node is the return annotation of a function,
- # in which case the scope is the parent scope of the function.
- if six.PY3 and node is parent.returns:
- return parent.parent.scope()
-
-
-@_scope_by_parent.register(treeabc.Comprehension)
-def _scope_by_comprehension_parent(parent, node):
- # Get the scope of a node which has a comprehension
- # as a parent. The rules are a bit hairy, but in essence
- # it is simple enough: list comprehensions leaks variables
- # on Python 2, so they have the parent scope of the list comprehension
- # itself. The iter part of the comprehension has almost always
- # another scope than the comprehension itself, but only for the
- # first generator (the outer one). Other comprehensions don't leak
- # variables on Python 2 and 3.
-
- comprehension = parent_scope = parent.parent
- generators = comprehension.generators
-
- # The first outer generator always has a different scope
- first_iter = generators[0].iter
- if node is first_iter:
- return parent_scope.parent.scope()
-
- # This might not be correct for all the cases, but it
- # should be enough for most of them.
- if six.PY2 and isinstance(parent_scope, treeabc.ListComp):
- return parent_scope.parent.scope()
- return parent.scope()
-
-
-@util.singledispatch
-def node_scope(node):
- """Get the scope of the given node."""
- scope = _scope_by_parent(node.parent, node)
- return scope or node.parent.scope()
-
-
-@node_scope.register(treeabc.Decorators)
-def _decorators_scope(node):
- return node.parent.parent.scope()
-
-
-@node_scope.register(treeabc.Module)
-@node_scope.register(treeabc.GeneratorExp)
-@node_scope.register(treeabc.DictComp)
-@node_scope.register(treeabc.SetComp)
-@node_scope.register(treeabc.Lambda)
-@node_scope.register(treeabc.FunctionDef)
-@node_scope.register(treeabc.ClassDef)
-def _scoped_nodes(node):
- return node
-
-if six.PY3:
- node_scope.register(treeabc.ListComp, _scoped_nodes)
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
+"""Implements logic for determing the scope of a node."""
+
+import itertools
+
+import six
+
+from astroid.tree import treeabc
+from astroid import util
+
+
+# import pdb; pdb.set_trace()
+
+@util.singledispatch
+def _scope_by_parent(parent, node):
+ """Detect the scope of the *node* by parent's rules.
+
+ The scope for certain kind of nodes depends on the
+ parent, as it is the case for default values of arguments
+ and function annotation, where the scope is not the scope of
+ the parent, but the parent scope of the parent.
+ """
+ # This is separated in multiple dispatch methods on parents,
+ # in order to decouple the implementation for the normal cases.
+
+
+def _node_arguments(node):
+ for arg in itertools.chain(node.positional_and_keyword, node.keyword_only,
+ (node.vararg, ), (node.kwarg, )):
+ if arg and arg.annotation:
+ yield arg
+
+
+@_scope_by_parent.register(treeabc.Arguments)
+def _scope_by_argument_parent(parent, node):
+ args = parent
+ for param in itertools.chain(args.positional_and_keyword, args.keyword_only):
+ if param.default == node:
+ return args.parent.parent.scope()
+
+ if six.PY3 and node in _node_arguments(args):
+ return args.parent.parent.scope()
+
+
+@_scope_by_parent.register(treeabc.FunctionDef)
+def _scope_by_function_parent(parent, node):
+ # Verify if the node is the return annotation of a function,
+ # in which case the scope is the parent scope of the function.
+ if six.PY3 and node is parent.returns:
+ return parent.parent.scope()
+
+
+@_scope_by_parent.register(treeabc.Comprehension)
+def _scope_by_comprehension_parent(parent, node):
+ # Get the scope of a node which has a comprehension
+ # as a parent. The rules are a bit hairy, but in essence
+ # it is simple enough: list comprehensions leaks variables
+ # on Python 2, so they have the parent scope of the list comprehension
+ # itself. The iter part of the comprehension has almost always
+ # another scope than the comprehension itself, but only for the
+ # first generator (the outer one). Other comprehensions don't leak
+ # variables on Python 2 and 3.
+
+ comprehension = parent_scope = parent.parent
+ generators = comprehension.generators
+
+ # The first outer generator always has a different scope
+ first_iter = generators[0].iter
+ if node is first_iter:
+ return parent_scope.parent.scope()
+
+ # This might not be correct for all the cases, but it
+ # should be enough for most of them.
+ if six.PY2 and isinstance(parent_scope, treeabc.ListComp):
+ return parent_scope.parent.scope()
+ return parent.scope()
+
+
+@util.singledispatch
+def node_scope(node):
+ """Get the scope of the given node."""
+ scope = _scope_by_parent(node.parent, node)
+ return scope or node.parent.scope()
+
+
+@node_scope.register(treeabc.Decorators)
+def _decorators_scope(node):
+ return node.parent.parent.scope()
+
+
+@node_scope.register(treeabc.Module)
+@node_scope.register(treeabc.GeneratorExp)
+@node_scope.register(treeabc.DictComp)
+@node_scope.register(treeabc.SetComp)
+@node_scope.register(treeabc.Lambda)
+@node_scope.register(treeabc.FunctionDef)
+@node_scope.register(treeabc.ClassDef)
+def _scoped_nodes(node):
+ return node
+
+if six.PY3:
+ node_scope.register(treeabc.ListComp, _scoped_nodes)
diff --git a/astroid/interpreter/util.py b/astroid/interpreter/util.py
index 207cd143..d5ba51de 100644
--- a/astroid/interpreter/util.py
+++ b/astroid/interpreter/util.py
@@ -1,20 +1,6 @@
-# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""Utilities for inference."""
import types
diff --git a/astroid/manager.py b/astroid/manager.py
index 73dd961a..24f353c8 100644
--- a/astroid/manager.py
+++ b/astroid/manager.py
@@ -1,20 +1,6 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""astroid manager: avoid multiple astroid build of a same module when
possible by providing a class responsible to get astroid representation
from various source and using a cache of built modules)
diff --git a/astroid/modutils.py b/astroid/modutils.py
index c6ff9385..da47d4c6 100644
--- a/astroid/modutils.py
+++ b/astroid/modutils.py
@@ -1,20 +1,6 @@
-# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it under
-# the terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option) any
-# later version.
-#
-# astroid is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""Python modules manipulation utility functions.
:type PY_SOURCE_EXTS: tuple(str)
diff --git a/astroid/nodes.py b/astroid/nodes.py
index 6fb37652..4fd5f4e7 100644
--- a/astroid/nodes.py
+++ b/astroid/nodes.py
@@ -1,20 +1,6 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""
on all nodes :
.is_statement, returning true if the node should be considered as a
diff --git a/astroid/protocols.py b/astroid/protocols.py
index 47741e33..da10b496 100644
--- a/astroid/protocols.py
+++ b/astroid/protocols.py
@@ -1,20 +1,6 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""this module contains a set of functions to handle python protocols for nodes
where it makes sense.
"""
diff --git a/astroid/raw_building.py b/astroid/raw_building.py
index f16bd6df..eb81cfb8 100644
--- a/astroid/raw_building.py
+++ b/astroid/raw_building.py
@@ -1,20 +1,6 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""this module contains a set of functions to create astroid trees from scratch
(build_* functions) or from living object (object_build_* functions)
"""
diff --git a/astroid/test_utils.py b/astroid/test_utils.py
index ff81cd59..8dd5bf4e 100644
--- a/astroid/test_utils.py
+++ b/astroid/test_utils.py
@@ -1,3 +1,6 @@
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""Utility functions for test code that uses astroid ASTs as input."""
import contextlib
import functools
diff --git a/astroid/tests/__init__.py b/astroid/tests/__init__.py
index e69de29b..7a8e4fce 100644
--- a/astroid/tests/__init__.py
+++ b/astroid/tests/__init__.py
@@ -0,0 +1,3 @@
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
diff --git a/astroid/tests/resources.py b/astroid/tests/resources.py
index 1390088c..461c8df1 100644
--- a/astroid/tests/resources.py
+++ b/astroid/tests/resources.py
@@ -1,20 +1,6 @@
-# Copyright 2014 Google, Inc. All rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
import binascii
import contextlib
import os
diff --git a/astroid/tests/unittest_brain.py b/astroid/tests/unittest_brain.py
index dd3e413e..766dc56e 100644
--- a/astroid/tests/unittest_brain.py
+++ b/astroid/tests/unittest_brain.py
@@ -1,19 +1,6 @@
-# Copyright 2013 Google Inc. All Rights Reserved.
-#
-# This file is part of astroid.
-#
-# logilab-astng is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# logilab-astng is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""Tests for basic functionality in astroid.brain."""
import sys
import unittest
diff --git a/astroid/tests/unittest_builder.py b/astroid/tests/unittest_builder.py
index 813c2e3d..dcb4e57c 100644
--- a/astroid/tests/unittest_builder.py
+++ b/astroid/tests/unittest_builder.py
@@ -1,20 +1,6 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""tests for the astroid builder and rebuilder module"""
import os
diff --git a/astroid/tests/unittest_helpers.py b/astroid/tests/unittest_helpers.py
index 6be6512a..efb25f0d 100644
--- a/astroid/tests/unittest_helpers.py
+++ b/astroid/tests/unittest_helpers.py
@@ -1,20 +1,6 @@
-# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
import types
import unittest
diff --git a/astroid/tests/unittest_inference.py b/astroid/tests/unittest_inference.py
index 7c8a58ea..5b05a3f6 100644
--- a/astroid/tests/unittest_inference.py
+++ b/astroid/tests/unittest_inference.py
@@ -1,20 +1,6 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""tests for the astroid inference capabilities
"""
import os
diff --git a/astroid/tests/unittest_lookup.py b/astroid/tests/unittest_lookup.py
index 2bdf5691..a376e3be 100644
--- a/astroid/tests/unittest_lookup.py
+++ b/astroid/tests/unittest_lookup.py
@@ -1,20 +1,6 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""tests for the astroid variable lookup capabilities
"""
import functools
diff --git a/astroid/tests/unittest_manager.py b/astroid/tests/unittest_manager.py
index 1b83862c..2cb64b9d 100644
--- a/astroid/tests/unittest_manager.py
+++ b/astroid/tests/unittest_manager.py
@@ -1,20 +1,6 @@
-# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
import os
import platform
import sys
diff --git a/astroid/tests/unittest_modutils.py b/astroid/tests/unittest_modutils.py
index 47c418bb..2b324229 100644
--- a/astroid/tests/unittest_modutils.py
+++ b/astroid/tests/unittest_modutils.py
@@ -1,20 +1,6 @@
-# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it under
-# the terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option) any
-# later version.
-#
-# astroid is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""
unit tests for module modutils (module manipulation utilities)
"""
diff --git a/astroid/tests/unittest_nodes.py b/astroid/tests/unittest_nodes.py
index 419df968..4a3a3146 100644
--- a/astroid/tests/unittest_nodes.py
+++ b/astroid/tests/unittest_nodes.py
@@ -1,20 +1,6 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""tests for specific behaviour of astroid nodes
"""
import os
diff --git a/astroid/tests/unittest_object_model.py b/astroid/tests/unittest_object_model.py
index 29a86781..03590fe5 100644
--- a/astroid/tests/unittest_object_model.py
+++ b/astroid/tests/unittest_object_model.py
@@ -1,20 +1,6 @@
-# copyright 2003-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
#
# The code in this file was originally part of logilab-common, licensed under
# the same license.
diff --git a/astroid/tests/unittest_objects.py b/astroid/tests/unittest_objects.py
index afcf76d3..f5c70c0f 100644
--- a/astroid/tests/unittest_objects.py
+++ b/astroid/tests/unittest_objects.py
@@ -1,580 +1,566 @@
-# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
-
-import unittest
-
-import six
-
-from astroid import exceptions
-from astroid import nodes
-from astroid.interpreter import objects
-from astroid import test_utils
-
-
-BUILTINS = six.moves.builtins.__name__
-
-
-class ObjectsTest(unittest.TestCase):
-
- def test_frozenset(self):
- node = test_utils.extract_node("""
- frozenset({1: 2, 2: 3}) #@
- """)
- inferred = next(node.infer())
- self.assertIsInstance(inferred, objects.FrozenSet)
-
- self.assertEqual(inferred.pytype(), "%s.frozenset" % BUILTINS)
-
- itered = inferred.itered()
- self.assertEqual(len(itered), 2)
- self.assertIsInstance(itered[0], nodes.Const)
- self.assertEqual([const.value for const in itered], [1, 2])
-
- proxied = inferred._proxied
- self.assertEqual(inferred.qname(), "%s.frozenset" % BUILTINS)
- self.assertIsInstance(proxied, nodes.ClassDef)
-
-
-class SuperTests(unittest.TestCase):
-
- def test_inferring_super_outside_methods(self):
- ast_nodes = test_utils.extract_node('''
- class Module(object):
- pass
- class StaticMethod(object):
- @staticmethod
- def static():
- # valid, but we don't bother with it.
- return super(StaticMethod, StaticMethod) #@
- # super outside methods aren't inferred
- super(Module, Module) #@
- # no argument super is not recognised outside methods as well.
- super() #@
- ''')
- in_static = next(ast_nodes[0].value.infer())
- self.assertIsInstance(in_static, objects.Instance)
- self.assertEqual(in_static.qname(), "%s.super" % BUILTINS)
-
- module_level = next(ast_nodes[1].infer())
- self.assertIsInstance(module_level, objects.Instance)
- self.assertEqual(in_static.qname(), "%s.super" % BUILTINS)
-
- no_arguments = next(ast_nodes[2].infer())
- self.assertIsInstance(no_arguments, objects.Instance)
- self.assertEqual(no_arguments.qname(), "%s.super" % BUILTINS)
-
- def test_inferring_unbound_super_doesnt_work(self):
- node = test_utils.extract_node('''
- class Test(object):
- def __init__(self):
- super(Test) #@
- ''')
- unbounded = next(node.infer())
- self.assertIsInstance(unbounded, objects.Instance)
- self.assertEqual(unbounded.qname(), "%s.super" % BUILTINS)
-
- def test_use_default_inference_on_not_inferring_args(self):
- ast_nodes = test_utils.extract_node('''
- class Test(object):
- def __init__(self):
- super(Lala, self) #@
- super(Test, lala) #@
- ''')
- first = next(ast_nodes[0].infer())
- self.assertIsInstance(first, objects.Instance)
- self.assertEqual(first.qname(), "%s.super" % BUILTINS)
-
- second = next(ast_nodes[1].infer())
- self.assertIsInstance(second, objects.Instance)
- self.assertEqual(second.qname(), "%s.super" % BUILTINS)
-
- @test_utils.require_version(maxver='3.0')
- def test_super_on_old_style_class(self):
- # super doesn't work on old style class, but leave
- # that as an error for pylint. We'll infer Super objects,
- # but every call will result in a failure at some point.
- node = test_utils.extract_node('''
- class OldStyle:
- def __init__(self):
- super(OldStyle, self) #@
- ''')
- old = next(node.infer())
- self.assertIsInstance(old, objects.Super)
- self.assertIsInstance(old.mro_pointer, nodes.ClassDef)
- self.assertEqual(old.mro_pointer.name, 'OldStyle')
- with self.assertRaises(exceptions.SuperError) as cm:
- old.super_mro()
- self.assertEqual(str(cm.exception),
- "Unable to call super on old-style classes.")
-
- @test_utils.require_version(minver='3.0')
- def test_no_arguments_super(self):
- ast_nodes = test_utils.extract_node('''
- class First(object): pass
- class Second(First):
- def test(self):
- super() #@
- @classmethod
- def test_classmethod(cls):
- super() #@
- ''')
- first = next(ast_nodes[0].infer())
- self.assertIsInstance(first, objects.Super)
- self.assertIsInstance(first.type, objects.Instance)
- self.assertEqual(first.type.name, 'Second')
- self.assertIsInstance(first.mro_pointer, nodes.ClassDef)
- self.assertEqual(first.mro_pointer.name, 'Second')
-
- second = next(ast_nodes[1].infer())
- self.assertIsInstance(second, objects.Super)
- self.assertIsInstance(second.type, nodes.ClassDef)
- self.assertEqual(second.type.name, 'Second')
- self.assertIsInstance(second.mro_pointer, nodes.ClassDef)
- self.assertEqual(second.mro_pointer.name, 'Second')
-
- def test_super_simple_cases(self):
- ast_nodes = test_utils.extract_node('''
- class First(object): pass
- class Second(First): pass
- class Third(First):
- def test(self):
- super(Third, self) #@
- super(Second, self) #@
-
- # mro position and the type
- super(Third, Third) #@
- super(Third, Second) #@
- super(Fourth, Fourth) #@
-
- class Fourth(Third):
- pass
- ''')
-
- # .type is the object which provides the mro.
- # .mro_pointer is the position in the mro from where
- # the lookup should be done.
-
- # super(Third, self)
- first = next(ast_nodes[0].infer())
- self.assertIsInstance(first, objects.Super)
- self.assertIsInstance(first.type, objects.Instance)
- self.assertEqual(first.type.name, 'Third')
- self.assertIsInstance(first.mro_pointer, nodes.ClassDef)
- self.assertEqual(first.mro_pointer.name, 'Third')
-
- # super(Second, self)
- second = next(ast_nodes[1].infer())
- self.assertIsInstance(second, objects.Super)
- self.assertIsInstance(second.type, objects.Instance)
- self.assertEqual(second.type.name, 'Third')
- self.assertIsInstance(first.mro_pointer, nodes.ClassDef)
- self.assertEqual(second.mro_pointer.name, 'Second')
-
- # super(Third, Third)
- third = next(ast_nodes[2].infer())
- self.assertIsInstance(third, objects.Super)
- self.assertIsInstance(third.type, nodes.ClassDef)
- self.assertEqual(third.type.name, 'Third')
- self.assertIsInstance(third.mro_pointer, nodes.ClassDef)
- self.assertEqual(third.mro_pointer.name, 'Third')
-
- # super(Third, second)
- fourth = next(ast_nodes[3].infer())
- self.assertIsInstance(fourth, objects.Super)
- self.assertIsInstance(fourth.type, nodes.ClassDef)
- self.assertEqual(fourth.type.name, 'Second')
- self.assertIsInstance(fourth.mro_pointer, nodes.ClassDef)
- self.assertEqual(fourth.mro_pointer.name, 'Third')
-
- # Super(Fourth, Fourth)
- fifth = next(ast_nodes[4].infer())
- self.assertIsInstance(fifth, objects.Super)
- self.assertIsInstance(fifth.type, nodes.ClassDef)
- self.assertEqual(fifth.type.name, 'Fourth')
- self.assertIsInstance(fifth.mro_pointer, nodes.ClassDef)
- self.assertEqual(fifth.mro_pointer.name, 'Fourth')
-
- def test_super_infer(self):
- node = test_utils.extract_node('''
- class Super(object):
- def __init__(self):
- super(Super, self) #@
- ''')
- inferred = next(node.infer())
- self.assertIsInstance(inferred, objects.Super)
- reinferred = next(inferred.infer())
- self.assertIsInstance(reinferred, objects.Super)
- self.assertIs(inferred, reinferred)
-
- def test_inferring_invalid_supers(self):
- ast_nodes = test_utils.extract_node('''
- class Super(object):
- def __init__(self):
- # MRO pointer is not a type
- super(1, self) #@
- # MRO type is not a subtype
- super(Super, 1) #@
- # self is not a subtype of Bupper
- super(Bupper, self) #@
- class Bupper(Super):
- pass
- ''')
- first = next(ast_nodes[0].infer())
- self.assertIsInstance(first, objects.Super)
- with self.assertRaises(exceptions.SuperError) as cm:
- first.super_mro()
- self.assertIsInstance(cm.exception.super_.mro_pointer, nodes.Const)
- self.assertEqual(cm.exception.super_.mro_pointer.value, 1)
- for node, invalid_type in zip(ast_nodes[1:],
- (nodes.Const, objects.Instance)):
- inferred = next(node.infer())
- self.assertIsInstance(inferred, objects.Super, node)
- with self.assertRaises(exceptions.SuperError) as cm:
- inferred.super_mro()
- self.assertIsInstance(cm.exception.super_.type, invalid_type)
-
- def test_proxied(self):
- node = test_utils.extract_node('''
- class Super(object):
- def __init__(self):
- super(Super, self) #@
- ''')
- inferred = next(node.infer())
- proxied = inferred._proxied
- self.assertEqual(proxied.qname(), "%s.super" % BUILTINS)
- self.assertIsInstance(proxied, nodes.ClassDef)
-
- def test_super_bound_model(self):
- ast_nodes = test_utils.extract_node('''
- class First(object):
- def method(self):
- pass
- @classmethod
- def class_method(cls):
- pass
- class Super_Type_Type(First):
- def method(self):
- super(Super_Type_Type, Super_Type_Type).method #@
- super(Super_Type_Type, Super_Type_Type).class_method #@
- @classmethod
- def class_method(cls):
- super(Super_Type_Type, Super_Type_Type).method #@
- super(Super_Type_Type, Super_Type_Type).class_method #@
-
- class Super_Type_Object(First):
- def method(self):
- super(Super_Type_Object, self).method #@
- super(Super_Type_Object, self).class_method #@
- ''')
- # Super(type, type) is the same for both functions and classmethods.
- first = next(ast_nodes[0].infer())
- self.assertIsInstance(first, nodes.FunctionDef)
- self.assertEqual(first.name, 'method')
-
- second = next(ast_nodes[1].infer())
- self.assertIsInstance(second, objects.BoundMethod)
- self.assertEqual(second.bound.name, 'First')
- self.assertEqual(second.type, 'classmethod')
-
- third = next(ast_nodes[2].infer())
- self.assertIsInstance(third, nodes.FunctionDef)
- self.assertEqual(third.name, 'method')
-
- fourth = next(ast_nodes[3].infer())
- self.assertIsInstance(fourth, objects.BoundMethod)
- self.assertEqual(fourth.bound.name, 'First')
- self.assertEqual(fourth.type, 'classmethod')
-
- # Super(type, obj) can lead to different attribute bindings
- # depending on the type of the place where super was called.
- fifth = next(ast_nodes[4].infer())
- self.assertIsInstance(fifth, objects.BoundMethod)
- self.assertEqual(fifth.bound.name, 'First')
- self.assertEqual(fifth.type, 'method')
-
- sixth = next(ast_nodes[5].infer())
- self.assertIsInstance(sixth, objects.BoundMethod)
- self.assertEqual(sixth.bound.name, 'First')
- self.assertEqual(sixth.type, 'classmethod')
-
- def test_super_getattr_single_inheritance(self):
- ast_nodes = test_utils.extract_node('''
- class First(object):
- def test(self): pass
- class Second(First):
- def test2(self): pass
- class Third(Second):
- test3 = 42
- def __init__(self):
- super(Third, self).test2 #@
- super(Third, self).test #@
- # test3 is local, no MRO lookup is done.
- super(Third, self).test3 #@
- super(Third, self) #@
-
- # Unbounds.
- super(Third, Third).test2 #@
- super(Third, Third).test #@
-
- ''')
- first = next(ast_nodes[0].infer())
- self.assertIsInstance(first, objects.BoundMethod)
- self.assertEqual(first.bound.name, 'Second')
-
- second = next(ast_nodes[1].infer())
- self.assertIsInstance(second, objects.BoundMethod)
- self.assertEqual(second.bound.name, 'First')
-
- with self.assertRaises(exceptions.InferenceError):
- next(ast_nodes[2].infer())
- fourth = next(ast_nodes[3].infer())
- with self.assertRaises(exceptions.AttributeInferenceError):
- fourth.getattr('test3')
- with self.assertRaises(exceptions.AttributeInferenceError):
- next(fourth.igetattr('test3'))
-
- first_unbound = next(ast_nodes[4].infer())
- self.assertIsInstance(first_unbound, nodes.FunctionDef)
- self.assertEqual(first_unbound.name, 'test2')
- self.assertEqual(first_unbound.parent.name, 'Second')
-
- second_unbound = next(ast_nodes[5].infer())
- self.assertIsInstance(second_unbound, nodes.FunctionDef)
- self.assertEqual(second_unbound.name, 'test')
- self.assertEqual(second_unbound.parent.name, 'First')
-
- def test_super_invalid_mro(self):
- node = test_utils.extract_node('''
- class A(object):
- test = 42
- class Super(A, A):
- def __init__(self):
- super(Super, self) #@
- ''')
- inferred = next(node.infer())
- with self.assertRaises(exceptions.AttributeInferenceError):
- next(inferred.getattr('test'))
-
- def test_super_complex_mro(self):
- ast_nodes = test_utils.extract_node('''
- class A(object):
- def spam(self): return "A"
- def foo(self): return "A"
- @staticmethod
- def static(self): pass
- class B(A):
- def boo(self): return "B"
- def spam(self): return "B"
- class C(A):
- def boo(self): return "C"
- class E(C, B):
- def __init__(self):
- super(E, self).boo #@
- super(C, self).boo #@
- super(E, self).spam #@
- super(E, self).foo #@
- super(E, self).static #@
- ''')
- first = next(ast_nodes[0].infer())
- self.assertIsInstance(first, objects.BoundMethod)
- self.assertEqual(first.bound.name, 'C')
- second = next(ast_nodes[1].infer())
- self.assertIsInstance(second, objects.BoundMethod)
- self.assertEqual(second.bound.name, 'B')
- third = next(ast_nodes[2].infer())
- self.assertIsInstance(third, objects.BoundMethod)
- self.assertEqual(third.bound.name, 'B')
- fourth = next(ast_nodes[3].infer())
- self.assertEqual(fourth.bound.name, 'A')
- static = next(ast_nodes[4].infer())
- self.assertIsInstance(static, nodes.FunctionDef)
- self.assertEqual(static.parent.scope().name, 'A')
-
- def test_super_data_model(self):
- ast_nodes = test_utils.extract_node('''
- class X(object): pass
- class A(X):
- def __init__(self):
- super(A, self) #@
- super(A, A) #@
- super(X, A) #@
- ''')
- first = next(ast_nodes[0].infer())
- thisclass = first.getattr('__thisclass__')[0]
- self.assertIsInstance(thisclass, nodes.ClassDef)
- self.assertEqual(thisclass.name, 'A')
- selfclass = first.getattr('__self_class__')[0]
- self.assertIsInstance(selfclass, nodes.ClassDef)
- self.assertEqual(selfclass.name, 'A')
- self_ = first.getattr('__self__')[0]
- self.assertIsInstance(self_, objects.Instance)
- self.assertEqual(self_.name, 'A')
- cls = first.getattr('__class__')[0]
- self.assertEqual(cls, first._proxied)
-
- second = next(ast_nodes[1].infer())
- thisclass = second.getattr('__thisclass__')[0]
- self.assertEqual(thisclass.name, 'A')
- self_ = second.getattr('__self__')[0]
- self.assertIsInstance(self_, nodes.ClassDef)
- self.assertEqual(self_.name, 'A')
-
- third = next(ast_nodes[2].infer())
- thisclass = third.getattr('__thisclass__')[0]
- self.assertEqual(thisclass.name, 'X')
- selfclass = third.getattr('__self_class__')[0]
- self.assertEqual(selfclass.name, 'A')
-
- def assertEqualMro(self, klass, expected_mro):
- self.assertEqual(
- [member.name for member in klass.super_mro()],
- expected_mro)
-
- def test_super_mro(self):
- ast_nodes = test_utils.extract_node('''
- class A(object): pass
- class B(A): pass
- class C(A): pass
- class E(C, B):
- def __init__(self):
- super(E, self) #@
- super(C, self) #@
- super(B, self) #@
-
- super(B, 1) #@
- super(1, B) #@
- ''')
- first = next(ast_nodes[0].infer())
- self.assertEqualMro(first, ['C', 'B', 'A', 'object'])
- second = next(ast_nodes[1].infer())
- self.assertEqualMro(second, ['B', 'A', 'object'])
- third = next(ast_nodes[2].infer())
- self.assertEqualMro(third, ['A', 'object'])
-
- fourth = next(ast_nodes[3].infer())
- with self.assertRaises(exceptions.SuperError):
- fourth.super_mro()
- fifth = next(ast_nodes[4].infer())
- with self.assertRaises(exceptions.SuperError):
- fifth.super_mro()
-
- def test_super_yes_objects(self):
- ast_nodes = test_utils.extract_node('''
- from collections import Missing
- class A(object):
- def __init__(self):
- super(Missing, self) #@
- super(A, Missing) #@
- ''')
- first = next(ast_nodes[0].infer())
- self.assertIsInstance(first, objects.Instance)
- second = next(ast_nodes[1].infer())
- self.assertIsInstance(second, objects.Instance)
-
- def test_super_invalid_types(self):
- node = test_utils.extract_node('''
- import collections
- class A(object):
- def __init__(self):
- super(A, collections) #@
- ''')
- inferred = next(node.infer())
- with self.assertRaises(exceptions.SuperError):
- inferred.super_mro()
- with self.assertRaises(exceptions.SuperError):
- inferred.super_mro()
-
- def test_super_properties(self):
- node = test_utils.extract_node('''
- class Foo(object):
- @property
- def dict(self):
- return 42
-
- class Bar(Foo):
- @property
- def dict(self):
- return super(Bar, self).dict
-
- Bar().dict
- ''')
- inferred = next(node.infer())
- self.assertIsInstance(inferred, nodes.Const)
- self.assertEqual(inferred.value, 42)
-
-
-class MethodTest(unittest.TestCase):
-
- def test_unbound_function_method_difference(self):
- node = test_utils.extract_node('''
- class A:
- def test(self): pass
- A.test
- ''')
- inferred = next(node.infer())
- if six.PY2:
- self.assertIsInstance(inferred, objects.UnboundMethod)
- else:
- self.assertIsInstance(inferred, nodes.FunctionDef)
-
- def test_unbound_function_from_classmethods(self):
- node = test_utils.extract_node('''
- class A:
- @classmethod
- def test(cls): return cls.b
- def b(self): return self
- A.test()
- ''')
- inferred = next(node.infer())
- if six.PY2:
- self.assertIsInstance(inferred, objects.UnboundMethod)
- else:
- self.assertIsInstance(inferred, nodes.FunctionDef)
-
- def test_static_method(self):
- node = test_utils.extract_node('''
- class A:
- @staticmethod
- def test(self): pass
- A.test
- ''')
- inferred = next(node.infer())
- self.assertIsInstance(inferred, nodes.FunctionDef)
-
- @unittest.skipUnless(six.PY2, "Unbound methods are available only on Python 2")
- def test_underlying_proxied_unbound_method(self):
- node = test_utils.extract_node('''
- class A:
- def test(self): pass
- A.test
- ''')
- inferred = next(node.infer())
- self.assertIsInstance(inferred._proxied, nodes.FunctionDef)
-
- def test_underlying_proxied_bound_method(self):
- node = test_utils.extract_node('''
- class A:
- def test(self): pass
- A().test
- ''')
- inferred = next(node.infer())
- self.assertIsInstance(inferred._proxied, nodes.FunctionDef)
-
-
-if __name__ == '__main__':
- unittest.main()
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
+
+import unittest
+
+import six
+
+from astroid import exceptions
+from astroid import nodes
+from astroid.interpreter import objects
+from astroid import test_utils
+
+
+BUILTINS = six.moves.builtins.__name__
+
+
+class ObjectsTest(unittest.TestCase):
+
+ def test_frozenset(self):
+ node = test_utils.extract_node("""
+ frozenset({1: 2, 2: 3}) #@
+ """)
+ inferred = next(node.infer())
+ self.assertIsInstance(inferred, objects.FrozenSet)
+
+ self.assertEqual(inferred.pytype(), "%s.frozenset" % BUILTINS)
+
+ itered = inferred.itered()
+ self.assertEqual(len(itered), 2)
+ self.assertIsInstance(itered[0], nodes.Const)
+ self.assertEqual([const.value for const in itered], [1, 2])
+
+ proxied = inferred._proxied
+ self.assertEqual(inferred.qname(), "%s.frozenset" % BUILTINS)
+ self.assertIsInstance(proxied, nodes.ClassDef)
+
+
+class SuperTests(unittest.TestCase):
+
+ def test_inferring_super_outside_methods(self):
+ ast_nodes = test_utils.extract_node('''
+ class Module(object):
+ pass
+ class StaticMethod(object):
+ @staticmethod
+ def static():
+ # valid, but we don't bother with it.
+ return super(StaticMethod, StaticMethod) #@
+ # super outside methods aren't inferred
+ super(Module, Module) #@
+ # no argument super is not recognised outside methods as well.
+ super() #@
+ ''')
+ in_static = next(ast_nodes[0].value.infer())
+ self.assertIsInstance(in_static, objects.Instance)
+ self.assertEqual(in_static.qname(), "%s.super" % BUILTINS)
+
+ module_level = next(ast_nodes[1].infer())
+ self.assertIsInstance(module_level, objects.Instance)
+ self.assertEqual(in_static.qname(), "%s.super" % BUILTINS)
+
+ no_arguments = next(ast_nodes[2].infer())
+ self.assertIsInstance(no_arguments, objects.Instance)
+ self.assertEqual(no_arguments.qname(), "%s.super" % BUILTINS)
+
+ def test_inferring_unbound_super_doesnt_work(self):
+ node = test_utils.extract_node('''
+ class Test(object):
+ def __init__(self):
+ super(Test) #@
+ ''')
+ unbounded = next(node.infer())
+ self.assertIsInstance(unbounded, objects.Instance)
+ self.assertEqual(unbounded.qname(), "%s.super" % BUILTINS)
+
+ def test_use_default_inference_on_not_inferring_args(self):
+ ast_nodes = test_utils.extract_node('''
+ class Test(object):
+ def __init__(self):
+ super(Lala, self) #@
+ super(Test, lala) #@
+ ''')
+ first = next(ast_nodes[0].infer())
+ self.assertIsInstance(first, objects.Instance)
+ self.assertEqual(first.qname(), "%s.super" % BUILTINS)
+
+ second = next(ast_nodes[1].infer())
+ self.assertIsInstance(second, objects.Instance)
+ self.assertEqual(second.qname(), "%s.super" % BUILTINS)
+
+ @test_utils.require_version(maxver='3.0')
+ def test_super_on_old_style_class(self):
+ # super doesn't work on old style class, but leave
+ # that as an error for pylint. We'll infer Super objects,
+ # but every call will result in a failure at some point.
+ node = test_utils.extract_node('''
+ class OldStyle:
+ def __init__(self):
+ super(OldStyle, self) #@
+ ''')
+ old = next(node.infer())
+ self.assertIsInstance(old, objects.Super)
+ self.assertIsInstance(old.mro_pointer, nodes.ClassDef)
+ self.assertEqual(old.mro_pointer.name, 'OldStyle')
+ with self.assertRaises(exceptions.SuperError) as cm:
+ old.super_mro()
+ self.assertEqual(str(cm.exception),
+ "Unable to call super on old-style classes.")
+
+ @test_utils.require_version(minver='3.0')
+ def test_no_arguments_super(self):
+ ast_nodes = test_utils.extract_node('''
+ class First(object): pass
+ class Second(First):
+ def test(self):
+ super() #@
+ @classmethod
+ def test_classmethod(cls):
+ super() #@
+ ''')
+ first = next(ast_nodes[0].infer())
+ self.assertIsInstance(first, objects.Super)
+ self.assertIsInstance(first.type, objects.Instance)
+ self.assertEqual(first.type.name, 'Second')
+ self.assertIsInstance(first.mro_pointer, nodes.ClassDef)
+ self.assertEqual(first.mro_pointer.name, 'Second')
+
+ second = next(ast_nodes[1].infer())
+ self.assertIsInstance(second, objects.Super)
+ self.assertIsInstance(second.type, nodes.ClassDef)
+ self.assertEqual(second.type.name, 'Second')
+ self.assertIsInstance(second.mro_pointer, nodes.ClassDef)
+ self.assertEqual(second.mro_pointer.name, 'Second')
+
+ def test_super_simple_cases(self):
+ ast_nodes = test_utils.extract_node('''
+ class First(object): pass
+ class Second(First): pass
+ class Third(First):
+ def test(self):
+ super(Third, self) #@
+ super(Second, self) #@
+
+ # mro position and the type
+ super(Third, Third) #@
+ super(Third, Second) #@
+ super(Fourth, Fourth) #@
+
+ class Fourth(Third):
+ pass
+ ''')
+
+ # .type is the object which provides the mro.
+ # .mro_pointer is the position in the mro from where
+ # the lookup should be done.
+
+ # super(Third, self)
+ first = next(ast_nodes[0].infer())
+ self.assertIsInstance(first, objects.Super)
+ self.assertIsInstance(first.type, objects.Instance)
+ self.assertEqual(first.type.name, 'Third')
+ self.assertIsInstance(first.mro_pointer, nodes.ClassDef)
+ self.assertEqual(first.mro_pointer.name, 'Third')
+
+ # super(Second, self)
+ second = next(ast_nodes[1].infer())
+ self.assertIsInstance(second, objects.Super)
+ self.assertIsInstance(second.type, objects.Instance)
+ self.assertEqual(second.type.name, 'Third')
+ self.assertIsInstance(first.mro_pointer, nodes.ClassDef)
+ self.assertEqual(second.mro_pointer.name, 'Second')
+
+ # super(Third, Third)
+ third = next(ast_nodes[2].infer())
+ self.assertIsInstance(third, objects.Super)
+ self.assertIsInstance(third.type, nodes.ClassDef)
+ self.assertEqual(third.type.name, 'Third')
+ self.assertIsInstance(third.mro_pointer, nodes.ClassDef)
+ self.assertEqual(third.mro_pointer.name, 'Third')
+
+ # super(Third, second)
+ fourth = next(ast_nodes[3].infer())
+ self.assertIsInstance(fourth, objects.Super)
+ self.assertIsInstance(fourth.type, nodes.ClassDef)
+ self.assertEqual(fourth.type.name, 'Second')
+ self.assertIsInstance(fourth.mro_pointer, nodes.ClassDef)
+ self.assertEqual(fourth.mro_pointer.name, 'Third')
+
+ # Super(Fourth, Fourth)
+ fifth = next(ast_nodes[4].infer())
+ self.assertIsInstance(fifth, objects.Super)
+ self.assertIsInstance(fifth.type, nodes.ClassDef)
+ self.assertEqual(fifth.type.name, 'Fourth')
+ self.assertIsInstance(fifth.mro_pointer, nodes.ClassDef)
+ self.assertEqual(fifth.mro_pointer.name, 'Fourth')
+
+ def test_super_infer(self):
+ node = test_utils.extract_node('''
+ class Super(object):
+ def __init__(self):
+ super(Super, self) #@
+ ''')
+ inferred = next(node.infer())
+ self.assertIsInstance(inferred, objects.Super)
+ reinferred = next(inferred.infer())
+ self.assertIsInstance(reinferred, objects.Super)
+ self.assertIs(inferred, reinferred)
+
+ def test_inferring_invalid_supers(self):
+ ast_nodes = test_utils.extract_node('''
+ class Super(object):
+ def __init__(self):
+ # MRO pointer is not a type
+ super(1, self) #@
+ # MRO type is not a subtype
+ super(Super, 1) #@
+ # self is not a subtype of Bupper
+ super(Bupper, self) #@
+ class Bupper(Super):
+ pass
+ ''')
+ first = next(ast_nodes[0].infer())
+ self.assertIsInstance(first, objects.Super)
+ with self.assertRaises(exceptions.SuperError) as cm:
+ first.super_mro()
+ self.assertIsInstance(cm.exception.super_.mro_pointer, nodes.Const)
+ self.assertEqual(cm.exception.super_.mro_pointer.value, 1)
+ for node, invalid_type in zip(ast_nodes[1:],
+ (nodes.Const, objects.Instance)):
+ inferred = next(node.infer())
+ self.assertIsInstance(inferred, objects.Super, node)
+ with self.assertRaises(exceptions.SuperError) as cm:
+ inferred.super_mro()
+ self.assertIsInstance(cm.exception.super_.type, invalid_type)
+
+ def test_proxied(self):
+ node = test_utils.extract_node('''
+ class Super(object):
+ def __init__(self):
+ super(Super, self) #@
+ ''')
+ inferred = next(node.infer())
+ proxied = inferred._proxied
+ self.assertEqual(proxied.qname(), "%s.super" % BUILTINS)
+ self.assertIsInstance(proxied, nodes.ClassDef)
+
+ def test_super_bound_model(self):
+ ast_nodes = test_utils.extract_node('''
+ class First(object):
+ def method(self):
+ pass
+ @classmethod
+ def class_method(cls):
+ pass
+ class Super_Type_Type(First):
+ def method(self):
+ super(Super_Type_Type, Super_Type_Type).method #@
+ super(Super_Type_Type, Super_Type_Type).class_method #@
+ @classmethod
+ def class_method(cls):
+ super(Super_Type_Type, Super_Type_Type).method #@
+ super(Super_Type_Type, Super_Type_Type).class_method #@
+
+ class Super_Type_Object(First):
+ def method(self):
+ super(Super_Type_Object, self).method #@
+ super(Super_Type_Object, self).class_method #@
+ ''')
+ # Super(type, type) is the same for both functions and classmethods.
+ first = next(ast_nodes[0].infer())
+ self.assertIsInstance(first, nodes.FunctionDef)
+ self.assertEqual(first.name, 'method')
+
+ second = next(ast_nodes[1].infer())
+ self.assertIsInstance(second, objects.BoundMethod)
+ self.assertEqual(second.bound.name, 'First')
+ self.assertEqual(second.type, 'classmethod')
+
+ third = next(ast_nodes[2].infer())
+ self.assertIsInstance(third, nodes.FunctionDef)
+ self.assertEqual(third.name, 'method')
+
+ fourth = next(ast_nodes[3].infer())
+ self.assertIsInstance(fourth, objects.BoundMethod)
+ self.assertEqual(fourth.bound.name, 'First')
+ self.assertEqual(fourth.type, 'classmethod')
+
+ # Super(type, obj) can lead to different attribute bindings
+ # depending on the type of the place where super was called.
+ fifth = next(ast_nodes[4].infer())
+ self.assertIsInstance(fifth, objects.BoundMethod)
+ self.assertEqual(fifth.bound.name, 'First')
+ self.assertEqual(fifth.type, 'method')
+
+ sixth = next(ast_nodes[5].infer())
+ self.assertIsInstance(sixth, objects.BoundMethod)
+ self.assertEqual(sixth.bound.name, 'First')
+ self.assertEqual(sixth.type, 'classmethod')
+
+ def test_super_getattr_single_inheritance(self):
+ ast_nodes = test_utils.extract_node('''
+ class First(object):
+ def test(self): pass
+ class Second(First):
+ def test2(self): pass
+ class Third(Second):
+ test3 = 42
+ def __init__(self):
+ super(Third, self).test2 #@
+ super(Third, self).test #@
+ # test3 is local, no MRO lookup is done.
+ super(Third, self).test3 #@
+ super(Third, self) #@
+
+ # Unbounds.
+ super(Third, Third).test2 #@
+ super(Third, Third).test #@
+
+ ''')
+ first = next(ast_nodes[0].infer())
+ self.assertIsInstance(first, objects.BoundMethod)
+ self.assertEqual(first.bound.name, 'Second')
+
+ second = next(ast_nodes[1].infer())
+ self.assertIsInstance(second, objects.BoundMethod)
+ self.assertEqual(second.bound.name, 'First')
+
+ with self.assertRaises(exceptions.InferenceError):
+ next(ast_nodes[2].infer())
+ fourth = next(ast_nodes[3].infer())
+ with self.assertRaises(exceptions.AttributeInferenceError):
+ fourth.getattr('test3')
+ with self.assertRaises(exceptions.AttributeInferenceError):
+ next(fourth.igetattr('test3'))
+
+ first_unbound = next(ast_nodes[4].infer())
+ self.assertIsInstance(first_unbound, nodes.FunctionDef)
+ self.assertEqual(first_unbound.name, 'test2')
+ self.assertEqual(first_unbound.parent.name, 'Second')
+
+ second_unbound = next(ast_nodes[5].infer())
+ self.assertIsInstance(second_unbound, nodes.FunctionDef)
+ self.assertEqual(second_unbound.name, 'test')
+ self.assertEqual(second_unbound.parent.name, 'First')
+
+ def test_super_invalid_mro(self):
+ node = test_utils.extract_node('''
+ class A(object):
+ test = 42
+ class Super(A, A):
+ def __init__(self):
+ super(Super, self) #@
+ ''')
+ inferred = next(node.infer())
+ with self.assertRaises(exceptions.AttributeInferenceError):
+ next(inferred.getattr('test'))
+
+ def test_super_complex_mro(self):
+ ast_nodes = test_utils.extract_node('''
+ class A(object):
+ def spam(self): return "A"
+ def foo(self): return "A"
+ @staticmethod
+ def static(self): pass
+ class B(A):
+ def boo(self): return "B"
+ def spam(self): return "B"
+ class C(A):
+ def boo(self): return "C"
+ class E(C, B):
+ def __init__(self):
+ super(E, self).boo #@
+ super(C, self).boo #@
+ super(E, self).spam #@
+ super(E, self).foo #@
+ super(E, self).static #@
+ ''')
+ first = next(ast_nodes[0].infer())
+ self.assertIsInstance(first, objects.BoundMethod)
+ self.assertEqual(first.bound.name, 'C')
+ second = next(ast_nodes[1].infer())
+ self.assertIsInstance(second, objects.BoundMethod)
+ self.assertEqual(second.bound.name, 'B')
+ third = next(ast_nodes[2].infer())
+ self.assertIsInstance(third, objects.BoundMethod)
+ self.assertEqual(third.bound.name, 'B')
+ fourth = next(ast_nodes[3].infer())
+ self.assertEqual(fourth.bound.name, 'A')
+ static = next(ast_nodes[4].infer())
+ self.assertIsInstance(static, nodes.FunctionDef)
+ self.assertEqual(static.parent.scope().name, 'A')
+
+ def test_super_data_model(self):
+ ast_nodes = test_utils.extract_node('''
+ class X(object): pass
+ class A(X):
+ def __init__(self):
+ super(A, self) #@
+ super(A, A) #@
+ super(X, A) #@
+ ''')
+ first = next(ast_nodes[0].infer())
+ thisclass = first.getattr('__thisclass__')[0]
+ self.assertIsInstance(thisclass, nodes.ClassDef)
+ self.assertEqual(thisclass.name, 'A')
+ selfclass = first.getattr('__self_class__')[0]
+ self.assertIsInstance(selfclass, nodes.ClassDef)
+ self.assertEqual(selfclass.name, 'A')
+ self_ = first.getattr('__self__')[0]
+ self.assertIsInstance(self_, objects.Instance)
+ self.assertEqual(self_.name, 'A')
+ cls = first.getattr('__class__')[0]
+ self.assertEqual(cls, first._proxied)
+
+ second = next(ast_nodes[1].infer())
+ thisclass = second.getattr('__thisclass__')[0]
+ self.assertEqual(thisclass.name, 'A')
+ self_ = second.getattr('__self__')[0]
+ self.assertIsInstance(self_, nodes.ClassDef)
+ self.assertEqual(self_.name, 'A')
+
+ third = next(ast_nodes[2].infer())
+ thisclass = third.getattr('__thisclass__')[0]
+ self.assertEqual(thisclass.name, 'X')
+ selfclass = third.getattr('__self_class__')[0]
+ self.assertEqual(selfclass.name, 'A')
+
+ def assertEqualMro(self, klass, expected_mro):
+ self.assertEqual(
+ [member.name for member in klass.super_mro()],
+ expected_mro)
+
+ def test_super_mro(self):
+ ast_nodes = test_utils.extract_node('''
+ class A(object): pass
+ class B(A): pass
+ class C(A): pass
+ class E(C, B):
+ def __init__(self):
+ super(E, self) #@
+ super(C, self) #@
+ super(B, self) #@
+
+ super(B, 1) #@
+ super(1, B) #@
+ ''')
+ first = next(ast_nodes[0].infer())
+ self.assertEqualMro(first, ['C', 'B', 'A', 'object'])
+ second = next(ast_nodes[1].infer())
+ self.assertEqualMro(second, ['B', 'A', 'object'])
+ third = next(ast_nodes[2].infer())
+ self.assertEqualMro(third, ['A', 'object'])
+
+ fourth = next(ast_nodes[3].infer())
+ with self.assertRaises(exceptions.SuperError):
+ fourth.super_mro()
+ fifth = next(ast_nodes[4].infer())
+ with self.assertRaises(exceptions.SuperError):
+ fifth.super_mro()
+
+ def test_super_yes_objects(self):
+ ast_nodes = test_utils.extract_node('''
+ from collections import Missing
+ class A(object):
+ def __init__(self):
+ super(Missing, self) #@
+ super(A, Missing) #@
+ ''')
+ first = next(ast_nodes[0].infer())
+ self.assertIsInstance(first, objects.Instance)
+ second = next(ast_nodes[1].infer())
+ self.assertIsInstance(second, objects.Instance)
+
+ def test_super_invalid_types(self):
+ node = test_utils.extract_node('''
+ import collections
+ class A(object):
+ def __init__(self):
+ super(A, collections) #@
+ ''')
+ inferred = next(node.infer())
+ with self.assertRaises(exceptions.SuperError):
+ inferred.super_mro()
+ with self.assertRaises(exceptions.SuperError):
+ inferred.super_mro()
+
+ def test_super_properties(self):
+ node = test_utils.extract_node('''
+ class Foo(object):
+ @property
+ def dict(self):
+ return 42
+
+ class Bar(Foo):
+ @property
+ def dict(self):
+ return super(Bar, self).dict
+
+ Bar().dict
+ ''')
+ inferred = next(node.infer())
+ self.assertIsInstance(inferred, nodes.Const)
+ self.assertEqual(inferred.value, 42)
+
+
+class MethodTest(unittest.TestCase):
+
+ def test_unbound_function_method_difference(self):
+ node = test_utils.extract_node('''
+ class A:
+ def test(self): pass
+ A.test
+ ''')
+ inferred = next(node.infer())
+ if six.PY2:
+ self.assertIsInstance(inferred, objects.UnboundMethod)
+ else:
+ self.assertIsInstance(inferred, nodes.FunctionDef)
+
+ def test_unbound_function_from_classmethods(self):
+ node = test_utils.extract_node('''
+ class A:
+ @classmethod
+ def test(cls): return cls.b
+ def b(self): return self
+ A.test()
+ ''')
+ inferred = next(node.infer())
+ if six.PY2:
+ self.assertIsInstance(inferred, objects.UnboundMethod)
+ else:
+ self.assertIsInstance(inferred, nodes.FunctionDef)
+
+ def test_static_method(self):
+ node = test_utils.extract_node('''
+ class A:
+ @staticmethod
+ def test(self): pass
+ A.test
+ ''')
+ inferred = next(node.infer())
+ self.assertIsInstance(inferred, nodes.FunctionDef)
+
+ @unittest.skipUnless(six.PY2, "Unbound methods are available only on Python 2")
+ def test_underlying_proxied_unbound_method(self):
+ node = test_utils.extract_node('''
+ class A:
+ def test(self): pass
+ A.test
+ ''')
+ inferred = next(node.infer())
+ self.assertIsInstance(inferred._proxied, nodes.FunctionDef)
+
+ def test_underlying_proxied_bound_method(self):
+ node = test_utils.extract_node('''
+ class A:
+ def test(self): pass
+ A().test
+ ''')
+ inferred = next(node.infer())
+ self.assertIsInstance(inferred._proxied, nodes.FunctionDef)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/astroid/tests/unittest_protocols.py b/astroid/tests/unittest_protocols.py
index cea39452..75b8d65b 100644
--- a/astroid/tests/unittest_protocols.py
+++ b/astroid/tests/unittest_protocols.py
@@ -1,20 +1,6 @@
-# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
import contextlib
import unittest
diff --git a/astroid/tests/unittest_python3.py b/astroid/tests/unittest_python3.py
index c5e3d353..d37f73dd 100644
--- a/astroid/tests/unittest_python3.py
+++ b/astroid/tests/unittest_python3.py
@@ -1,20 +1,6 @@
-# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
from textwrap import dedent
import unittest
diff --git a/astroid/tests/unittest_raw_building.py b/astroid/tests/unittest_raw_building.py
index a2846473..bf4b762a 100644
--- a/astroid/tests/unittest_raw_building.py
+++ b/astroid/tests/unittest_raw_building.py
@@ -1,3 +1,6 @@
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
import inspect
import os
import unittest
diff --git a/astroid/tests/unittest_regrtest.py b/astroid/tests/unittest_regrtest.py
index d99a74d0..66613d75 100644
--- a/astroid/tests/unittest_regrtest.py
+++ b/astroid/tests/unittest_regrtest.py
@@ -1,20 +1,6 @@
-# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
import sys
import unittest
import textwrap
diff --git a/astroid/tests/unittest_scoped_nodes.py b/astroid/tests/unittest_scoped_nodes.py
index c0db1396..4294a844 100644
--- a/astroid/tests/unittest_scoped_nodes.py
+++ b/astroid/tests/unittest_scoped_nodes.py
@@ -1,20 +1,6 @@
-# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""tests for specific behaviour of astroid scoped nodes (i.e. module, class and
function)
"""
diff --git a/astroid/tests/unittest_transforms.py b/astroid/tests/unittest_transforms.py
index 6bcb1db0..285aafdc 100644
--- a/astroid/tests/unittest_transforms.py
+++ b/astroid/tests/unittest_transforms.py
@@ -1,245 +1,231 @@
-# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
-
-from __future__ import print_function
-
-import contextlib
-import time
-import unittest
-
-from astroid import builder
-from astroid import nodes
-from astroid import parse
-from astroid import transforms
-
-
-@contextlib.contextmanager
-def add_transform(manager, node, transform, predicate=None):
- manager.register_transform(node, transform, predicate)
- try:
- yield
- finally:
- manager.unregister_transform(node, transform, predicate)
-
-
-class TestTransforms(unittest.TestCase):
-
- def setUp(self):
- self.transformer = transforms.TransformVisitor()
-
- def parse_transform(self, code):
- module = parse(code, apply_transforms=False)
- return self.transformer.visit(module)
-
- def test_function_inlining_transform(self):
- def transform_call(node):
- # Let's do some function inlining
- inferred = next(node.infer())
- return inferred
-
- self.transformer.register_transform(nodes.Call,
- transform_call)
-
- module = self.parse_transform('''
- def test(): return 42
- test() #@
- ''')
-
- self.assertIsInstance(module.body[1], nodes.Expr)
- self.assertIsInstance(module.body[1].value, nodes.Const)
- self.assertEqual(module.body[1].value.value, 42)
-
- def test_recursive_transforms_into_astroid_fields(self):
- # Test that the transformer walks properly the tree
- # by going recursively into the _astroid_fields per each node.
- def transform_compare(node):
- # Let's check the values of the ops
- right = node.comparators[0]
- # Assume they are Consts and they were transformed before
- # us.
- return nodes.Const(node.left.value < right.value)
-
- def transform_name(node):
- # Should be Consts
- return next(node.infer())
-
- self.transformer.register_transform(nodes.Compare, transform_compare)
- self.transformer.register_transform(nodes.Name, transform_name)
-
- module = self.parse_transform('''
- a = 42
- b = 24
- a < b
- ''')
-
- self.assertIsInstance(module.body[2], nodes.Expr)
- self.assertIsInstance(module.body[2].value, nodes.Const)
- self.assertFalse(module.body[2].value.value)
-
- def test_transform_patches_locals(self):
- def transform_function(node):
- assign = nodes.Assign()
- name = nodes.AssignName()
- name.name = 'value'
- assign.targets = [name]
- assign.value = nodes.Const(42)
- node.body.append(assign)
-
- self.transformer.register_transform(nodes.FunctionDef,
- transform_function)
-
- module = self.parse_transform('''
- def test():
- pass
- ''')
-
- func = module.body[0]
- self.assertEqual(len(func.body), 2)
- self.assertIsInstance(func.body[1], nodes.Assign)
- self.assertEqual(func.body[1].as_string(), 'value = 42')
-
- def test_predicates(self):
- def transform_call(node):
- inferred = next(node.infer())
- return inferred
-
- def should_inline(node):
- return node.func.name.startswith('inlineme')
-
- self.transformer.register_transform(nodes.Call,
- transform_call,
- should_inline)
-
- module = self.parse_transform('''
- def inlineme_1():
- return 24
- def dont_inline_me():
- return 42
- def inlineme_2():
- return 2
- inlineme_1()
- dont_inline_me()
- inlineme_2()
- ''')
- values = module.body[-3:]
- self.assertIsInstance(values[0], nodes.Expr)
- self.assertIsInstance(values[0].value, nodes.Const)
- self.assertEqual(values[0].value.value, 24)
- self.assertIsInstance(values[1], nodes.Expr)
- self.assertIsInstance(values[1].value, nodes.Call)
- self.assertIsInstance(values[2], nodes.Expr)
- self.assertIsInstance(values[2].value, nodes.Const)
- self.assertEqual(values[2].value.value, 2)
-
- def test_transforms_are_separated(self):
- # Test that the transforming is done at a separate
- # step, which means that we are not doing inference
- # on a partially constructred tree anymore, which was the
- # source of crashes in the past when certain inference rules
- # were used in a transform.
- def transform_function(node):
- if node.decorators:
- for decorator in node.decorators.nodes:
- inferred = next(decorator.infer())
- if inferred.qname() == 'abc.abstractmethod':
- return next(node.infer_call_result(node))
-
- manager = builder.MANAGER
- with add_transform(manager, nodes.FunctionDef, transform_function):
- module = builder.parse('''
- import abc
- from abc import abstractmethod
-
- class A(object):
- @abc.abstractmethod
- def ala(self):
- return 24
-
- @abstractmethod
- def bala(self):
- return 42
- ''')
-
- cls = module['A']
- ala = cls.body[0]
- bala = cls.body[1]
- self.assertIsInstance(ala, nodes.Const)
- self.assertEqual(ala.value, 24)
- self.assertIsInstance(bala, nodes.Const)
- self.assertEqual(bala.value, 42)
-
- def test_transforms_are_called_for_builtin_modules(self):
- # Test that transforms are called for builtin modules.
- def transform_function(node):
- name = nodes.AssignName()
- name.name = 'value'
- node.args.args = [name]
- return node
-
- manager = builder.MANAGER
- predicate = lambda node: node.root().name == 'time'
- with add_transform(manager, nodes.FunctionDef,
- transform_function, predicate):
- builder_instance = builder.AstroidBuilder()
- module = builder_instance.module_build(time)
-
- asctime = module['asctime']
- self.assertEqual(len(asctime.args.args), 1)
- self.assertIsInstance(asctime.args.args[0], nodes.AssignName)
- self.assertEqual(asctime.args.args[0].name, 'value')
-
- def test_builder_apply_transforms(self):
- def transform_function(node):
- return nodes.Const(42)
-
- manager = builder.MANAGER
- with add_transform(manager, nodes.FunctionDef, transform_function):
- astroid_builder = builder.AstroidBuilder(apply_transforms=False)
- module = astroid_builder.string_build('''def test(): pass''')
-
- # The transform wasn't applied.
- self.assertIsInstance(module.body[0], nodes.FunctionDef)
-
- def test_transform_crashes_on_is_subtype_of(self):
- # Test that we don't crash when having is_subtype_of
- # in a transform, as per issue #188. This happened
- # before, when the transforms weren't in their own step.
- def transform_class(cls):
- if cls.is_subtype_of('django.db.models.base.Model'):
- return cls
- return cls
-
- self.transformer.register_transform(nodes.ClassDef,
- transform_class)
-
- self.parse_transform('''
- # Change environ to automatically call putenv() if it exists
- import os
- putenv = os.putenv
- try:
- # This will fail if there's no putenv
- putenv
- except NameError:
- pass
- else:
- import UserDict
- ''')
-
-
-if __name__ == '__main__':
- unittest.main()
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
+
+from __future__ import print_function
+
+import contextlib
+import time
+import unittest
+
+from astroid import builder
+from astroid import nodes
+from astroid import parse
+from astroid import transforms
+
+
+@contextlib.contextmanager
+def add_transform(manager, node, transform, predicate=None):
+ manager.register_transform(node, transform, predicate)
+ try:
+ yield
+ finally:
+ manager.unregister_transform(node, transform, predicate)
+
+
+class TestTransforms(unittest.TestCase):
+
+ def setUp(self):
+ self.transformer = transforms.TransformVisitor()
+
+ def parse_transform(self, code):
+ module = parse(code, apply_transforms=False)
+ return self.transformer.visit(module)
+
+ def test_function_inlining_transform(self):
+ def transform_call(node):
+ # Let's do some function inlining
+ inferred = next(node.infer())
+ return inferred
+
+ self.transformer.register_transform(nodes.Call,
+ transform_call)
+
+ module = self.parse_transform('''
+ def test(): return 42
+ test() #@
+ ''')
+
+ self.assertIsInstance(module.body[1], nodes.Expr)
+ self.assertIsInstance(module.body[1].value, nodes.Const)
+ self.assertEqual(module.body[1].value.value, 42)
+
+ def test_recursive_transforms_into_astroid_fields(self):
+ # Test that the transformer walks properly the tree
+ # by going recursively into the _astroid_fields per each node.
+ def transform_compare(node):
+ # Let's check the values of the ops
+ right = node.comparators[0]
+ # Assume they are Consts and they were transformed before
+ # us.
+ return nodes.Const(node.left.value < right.value)
+
+ def transform_name(node):
+ # Should be Consts
+ return next(node.infer())
+
+ self.transformer.register_transform(nodes.Compare, transform_compare)
+ self.transformer.register_transform(nodes.Name, transform_name)
+
+ module = self.parse_transform('''
+ a = 42
+ b = 24
+ a < b
+ ''')
+
+ self.assertIsInstance(module.body[2], nodes.Expr)
+ self.assertIsInstance(module.body[2].value, nodes.Const)
+ self.assertFalse(module.body[2].value.value)
+
+ def test_transform_patches_locals(self):
+ def transform_function(node):
+ assign = nodes.Assign()
+ name = nodes.AssignName()
+ name.name = 'value'
+ assign.targets = [name]
+ assign.value = nodes.Const(42)
+ node.body.append(assign)
+
+ self.transformer.register_transform(nodes.FunctionDef,
+ transform_function)
+
+ module = self.parse_transform('''
+ def test():
+ pass
+ ''')
+
+ func = module.body[0]
+ self.assertEqual(len(func.body), 2)
+ self.assertIsInstance(func.body[1], nodes.Assign)
+ self.assertEqual(func.body[1].as_string(), 'value = 42')
+
+ def test_predicates(self):
+ def transform_call(node):
+ inferred = next(node.infer())
+ return inferred
+
+ def should_inline(node):
+ return node.func.name.startswith('inlineme')
+
+ self.transformer.register_transform(nodes.Call,
+ transform_call,
+ should_inline)
+
+ module = self.parse_transform('''
+ def inlineme_1():
+ return 24
+ def dont_inline_me():
+ return 42
+ def inlineme_2():
+ return 2
+ inlineme_1()
+ dont_inline_me()
+ inlineme_2()
+ ''')
+ values = module.body[-3:]
+ self.assertIsInstance(values[0], nodes.Expr)
+ self.assertIsInstance(values[0].value, nodes.Const)
+ self.assertEqual(values[0].value.value, 24)
+ self.assertIsInstance(values[1], nodes.Expr)
+ self.assertIsInstance(values[1].value, nodes.Call)
+ self.assertIsInstance(values[2], nodes.Expr)
+ self.assertIsInstance(values[2].value, nodes.Const)
+ self.assertEqual(values[2].value.value, 2)
+
+ def test_transforms_are_separated(self):
+ # Test that the transforming is done at a separate
+ # step, which means that we are not doing inference
+ # on a partially constructred tree anymore, which was the
+ # source of crashes in the past when certain inference rules
+ # were used in a transform.
+ def transform_function(node):
+ if node.decorators:
+ for decorator in node.decorators.nodes:
+ inferred = next(decorator.infer())
+ if inferred.qname() == 'abc.abstractmethod':
+ return next(node.infer_call_result(node))
+
+ manager = builder.MANAGER
+ with add_transform(manager, nodes.FunctionDef, transform_function):
+ module = builder.parse('''
+ import abc
+ from abc import abstractmethod
+
+ class A(object):
+ @abc.abstractmethod
+ def ala(self):
+ return 24
+
+ @abstractmethod
+ def bala(self):
+ return 42
+ ''')
+
+ cls = module['A']
+ ala = cls.body[0]
+ bala = cls.body[1]
+ self.assertIsInstance(ala, nodes.Const)
+ self.assertEqual(ala.value, 24)
+ self.assertIsInstance(bala, nodes.Const)
+ self.assertEqual(bala.value, 42)
+
+ def test_transforms_are_called_for_builtin_modules(self):
+ # Test that transforms are called for builtin modules.
+ def transform_function(node):
+ name = nodes.AssignName()
+ name.name = 'value'
+ node.args.args = [name]
+ return node
+
+ manager = builder.MANAGER
+ predicate = lambda node: node.root().name == 'time'
+ with add_transform(manager, nodes.FunctionDef,
+ transform_function, predicate):
+ builder_instance = builder.AstroidBuilder()
+ module = builder_instance.module_build(time)
+
+ asctime = module['asctime']
+ self.assertEqual(len(asctime.args.args), 1)
+ self.assertIsInstance(asctime.args.args[0], nodes.AssignName)
+ self.assertEqual(asctime.args.args[0].name, 'value')
+
+ def test_builder_apply_transforms(self):
+ def transform_function(node):
+ return nodes.Const(42)
+
+ manager = builder.MANAGER
+ with add_transform(manager, nodes.FunctionDef, transform_function):
+ astroid_builder = builder.AstroidBuilder(apply_transforms=False)
+ module = astroid_builder.string_build('''def test(): pass''')
+
+ # The transform wasn't applied.
+ self.assertIsInstance(module.body[0], nodes.FunctionDef)
+
+ def test_transform_crashes_on_is_subtype_of(self):
+ # Test that we don't crash when having is_subtype_of
+ # in a transform, as per issue #188. This happened
+ # before, when the transforms weren't in their own step.
+ def transform_class(cls):
+ if cls.is_subtype_of('django.db.models.base.Model'):
+ return cls
+ return cls
+
+ self.transformer.register_transform(nodes.ClassDef,
+ transform_class)
+
+ self.parse_transform('''
+ # Change environ to automatically call putenv() if it exists
+ import os
+ putenv = os.putenv
+ try:
+ # This will fail if there's no putenv
+ putenv
+ except NameError:
+ pass
+ else:
+ import UserDict
+ ''')
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/astroid/tests/unittest_utils.py b/astroid/tests/unittest_utils.py
index 81777e37..8cef049c 100644
--- a/astroid/tests/unittest_utils.py
+++ b/astroid/tests/unittest_utils.py
@@ -1,20 +1,6 @@
-# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
import unittest
from astroid import builder
diff --git a/astroid/transforms.py b/astroid/transforms.py
index 5d8fc91b..83243ad0 100644
--- a/astroid/transforms.py
+++ b/astroid/transforms.py
@@ -1,20 +1,6 @@
-# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
import collections
import warnings
diff --git a/astroid/tree/__init__.py b/astroid/tree/__init__.py
index e69de29b..7a8e4fce 100644
--- a/astroid/tree/__init__.py
+++ b/astroid/tree/__init__.py
@@ -0,0 +1,3 @@
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
diff --git a/astroid/tree/base.py b/astroid/tree/base.py
index 58298b8d..3fe98997 100644
--- a/astroid/tree/base.py
+++ b/astroid/tree/base.py
@@ -1,20 +1,6 @@
-# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
import abc
import pprint
diff --git a/astroid/tree/node_classes.py b/astroid/tree/node_classes.py
index a5ba8c88..47d9d047 100644
--- a/astroid/tree/node_classes.py
+++ b/astroid/tree/node_classes.py
@@ -1,20 +1,6 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""Module for some node classes. More nodes in scoped_nodes.py
"""
diff --git a/astroid/tree/rebuilder.py b/astroid/tree/rebuilder.py
index 074aea1e..d5324e7d 100644
--- a/astroid/tree/rebuilder.py
+++ b/astroid/tree/rebuilder.py
@@ -1,20 +1,6 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""this module contains utilities for rebuilding a ast tree in
order to get a single Astroid representation
"""
diff --git a/astroid/tree/scoped_nodes.py b/astroid/tree/scoped_nodes.py
index 7bdc8aab..627903c8 100644
--- a/astroid/tree/scoped_nodes.py
+++ b/astroid/tree/scoped_nodes.py
@@ -1,20 +1,6 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""
This module contains the classes for "scoped" node, i.e. which are opening a
diff --git a/astroid/tree/treeabc.py b/astroid/tree/treeabc.py
index 5c008255..22e6aeb8 100644
--- a/astroid/tree/treeabc.py
+++ b/astroid/tree/treeabc.py
@@ -1,20 +1,6 @@
-# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
"""Abstract classes for nodes and other runtime objects.
diff --git a/astroid/util.py b/astroid/util.py
index 21c99469..c3b3fc1a 100644
--- a/astroid/util.py
+++ b/astroid/util.py
@@ -1,20 +1,6 @@
-# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of astroid.
-#
-# astroid is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation, either version 2.1 of the License, or (at your
-# option) any later version.
-#
-# astroid is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
-# for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+
#
# The code in this file was originally part of logilab-common, licensed under
# the same license.