Skip to content

Commit

Permalink
Merge 4804d71 into 0bd5e82
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Apr 19, 2021
2 parents 0bd5e82 + 4804d71 commit 5bc7d63
Show file tree
Hide file tree
Showing 77 changed files with 319 additions and 399 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ astroid.egg-info/
.eggs/
.pytest_cache/
.mypy_cache/
venv
25 changes: 25 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
repos:
- repo: https://github.com/myint/autoflake
rev: v1.4
hooks:
- id: autoflake
exclude: tests/testdata|astroid/__init__.py
args:
- --in-place
- --remove-all-unused-imports
- --expand-star-imports
- --remove-duplicate-keys
- --remove-unused-variables
- repo: https://github.com/PyCQA/isort
rev: 5.8.0
hooks:
- id: isort
exclude: tests/testdata|astroid/__init__.py
- repo: https://github.com/asottile/pyupgrade
rev: v2.12.0
hooks:
Expand All @@ -23,3 +39,12 @@ repos:
hooks:
- id: prettier
args: [--prose-wrap=always, --print-width=88]
- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
args: ["-rn", "-sn", "--rcfile=pylintrc"]
exclude: tests/testdata|setup.py|conf.py
8 changes: 2 additions & 6 deletions astroid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,16 @@

import wrapt

from .__pkginfo__ import version as __version__

_Context = enum.Enum("Context", "Load Store Del")
Load = _Context.Load
Store = _Context.Store
Del = _Context.Del
del _Context


# pylint: disable=wrong-import-order,wrong-import-position
from .__pkginfo__ import version as __version__

# WARNING: internal imports order matters !

# pylint: disable=redefined-builtin
# pylint: disable=wrong-import-order,wrong-import-position,redefined-builtin

# make all exception classes accessible from astroid package
from astroid.exceptions import *
Expand Down
2 changes: 1 addition & 1 deletion astroid/_ast.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import ast
import sys
from collections import namedtuple
from functools import partial
from typing import Optional
import sys

import astroid

Expand Down
4 changes: 1 addition & 3 deletions astroid/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

from astroid import bases
from astroid import context as contextmod
from astroid import exceptions
from astroid import nodes
from astroid import util
from astroid import exceptions, nodes, util


class CallSite:
Expand Down
3 changes: 1 addition & 2 deletions astroid/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
import collections

from astroid import context as contextmod
from astroid import exceptions
from astroid import util
from astroid import exceptions, util

objectmodel = util.lazy_import("interpreter.objectmodel")
helpers = util.lazy_import("helpers")
Expand Down
Empty file added astroid/brain/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion astroid/brain/brain_argparse.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from astroid import MANAGER, arguments, nodes, inference_tip, UseInferenceDefault
from astroid import MANAGER, UseInferenceDefault, arguments, inference_tip, nodes


def infer_namespace(node, context=None):
Expand Down
1 change: 0 additions & 1 deletion astroid/brain/brain_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import astroid
from astroid import MANAGER


ATTRIB_NAMES = frozenset(("attr.ib", "attrib", "attr.attrib"))
ATTRS_NAMES = frozenset(("attr.s", "attrs", "attr.attrs", "attr.attributes"))

Expand Down
37 changes: 18 additions & 19 deletions astroid/brain/brain_builtin_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,21 @@

from astroid import (
MANAGER,
UseInferenceDefault,
AstroidTypeError,
AttributeInferenceError,
inference_tip,
InferenceError,
NameInferenceError,
AstroidTypeError,
MroError,
NameInferenceError,
UseInferenceDefault,
arguments,
helpers,
inference_tip,
nodes,
objects,
scoped_nodes,
util,
)
from astroid import arguments
from astroid.builder import AstroidBuilder
from astroid import helpers
from astroid import nodes
from astroid import objects
from astroid import scoped_nodes
from astroid import util


OBJECT_DUNDER_NEW = "object.__new__"

Expand Down Expand Up @@ -232,10 +231,12 @@ def _container_generic_inference(node, context, node_type, transform):
return transformed


def _container_generic_transform(arg, context, klass, iterables, build_elts):
def _container_generic_transform( # pylint: disable=inconsistent-return-statements
arg, context, klass, iterables, build_elts
):
if isinstance(arg, klass):
return arg
elif isinstance(arg, iterables):
if isinstance(arg, iterables):
if all(isinstance(elt, nodes.Const) for elt in arg.elts):
elts = [elt.value for elt in arg.elts]
else:
Expand Down Expand Up @@ -371,7 +372,7 @@ def infer_dict(node, context=None):
if not args and not kwargs:
# dict()
return nodes.Dict()
elif kwargs and not args:
if kwargs and not args:
# dict(a=1, b=2, c=4)
items = [(nodes.Const(key), value) for key, value in kwargs]
elif len(args) == 1 and kwargs:
Expand All @@ -383,7 +384,6 @@ def infer_dict(node, context=None):
items = _get_elts(args[0], context)
else:
raise UseInferenceDefault()

value = nodes.Dict(
col_offset=node.col_offset, lineno=node.lineno, parent=node.parent
)
Expand Down Expand Up @@ -417,7 +417,7 @@ def infer_super(node, context=None):
raise UseInferenceDefault

cls = scoped_nodes.get_wrapping_class(scope)
if not len(node.args):
if not node.args:
mro_pointer = cls
# In we are in a classmethod, the interpreter will fill
# automatically the class as the second argument, not an instance.
Expand Down Expand Up @@ -877,15 +877,14 @@ def _build_dict_with_elements(elements):

elements_with_value = [(element, default) for element in elements]
return _build_dict_with_elements(elements_with_value)

elif isinstance(inferred_values, nodes.Const) and isinstance(
if isinstance(inferred_values, nodes.Const) and isinstance(
inferred_values.value, (str, bytes)
):
elements = [
(nodes.Const(element), default) for element in inferred_values.value
]
return _build_dict_with_elements(elements)
elif isinstance(inferred_values, nodes.Dict):
if isinstance(inferred_values, nodes.Dict):
keys = inferred_values.itered()
for key in keys:
if not isinstance(key, accepted_iterable_elements):
Expand Down
1 change: 0 additions & 1 deletion astroid/brain/brain_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import astroid


PY39 = sys.version_info >= (3, 9)


Expand Down
1 change: 1 addition & 0 deletions astroid/brain/brain_crypt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 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/LICENSE
import sys

import astroid

PY37 = sys.version_info >= (3, 7)
Expand Down
1 change: 0 additions & 1 deletion astroid/brain/brain_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import astroid
from astroid import MANAGER


DATACLASSES_DECORATORS = frozenset(("dataclasses.dataclass", "dataclass"))


Expand Down
2 changes: 1 addition & 1 deletion astroid/brain/brain_fstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _clone_node_with_lineno(node, parent, lineno):
return new_node


def _transform_formatted_value(node):
def _transform_formatted_value(node): # pylint: disable=inconsistent-return-statements
if node.value and node.value.lineno == 1:
if node.lineno != node.value.lineno:
new_node = astroid.FormattedValue(
Expand Down
16 changes: 5 additions & 11 deletions astroid/brain/brain_functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,8 @@
from itertools import chain

import astroid
from astroid import arguments
from astroid import BoundMethod
from astroid import extract_node
from astroid import helpers
from astroid import MANAGER, BoundMethod, arguments, extract_node, helpers, objects
from astroid.interpreter import objectmodel
from astroid import MANAGER
from astroid import objects


LRU_CACHE = "functools.lru_cache"

Expand Down Expand Up @@ -52,15 +46,14 @@ def attr_cache_clear(self):
return BoundMethod(proxy=node, bound=self._instance.parent.scope())


def _transform_lru_cache(node, context=None):
def _transform_lru_cache(node, context=None) -> None:
# TODO: this is not ideal, since the node should be immutable,
# but due to https://github.com/PyCQA/astroid/issues/354,
# there's not much we can do now.
# Replacing the node would work partially, because,
# in pylint, the old node would still be available, leading
# to spurious false positives.
node.special_attributes = LruWrappedModel()(node)
return


def _functools_partial_inference(node, context=None):
Expand Down Expand Up @@ -136,16 +129,17 @@ def _looks_like_lru_cache(node):
return False


def _looks_like_functools_member(node, member):
def _looks_like_functools_member(node, member) -> bool:
"""Check if the given Call node is a functools.partial call"""
if isinstance(node.func, astroid.Name):
return node.func.name == member
elif isinstance(node.func, astroid.Attribute):
if isinstance(node.func, astroid.Attribute):
return (
node.func.attrname == member
and isinstance(node.func.expr, astroid.Name)
and node.func.expr.name == "functools"
)
return False


_looks_like_partial = partial(_looks_like_functools_member, member="partial")
Expand Down
16 changes: 10 additions & 6 deletions astroid/brain/brain_gi.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
Helps with understanding everything imported from 'gi.repository'
"""

# pylint:disable=import-error,import-outside-toplevel

import inspect
import itertools
import sys
import re
import sys
import warnings

from astroid import MANAGER, AstroidBuildingError, nodes
from astroid.builder import AstroidBuilder


_inspected_modules = {}

_identifier_re = r"^[A-Za-z_]\w*$"
Expand Down Expand Up @@ -83,7 +84,7 @@ def _gi_build_stub(parent):

try:
obj = getattr(parent, name)
except:
except AttributeError:
continue

if inspect.isclass(obj):
Expand Down Expand Up @@ -188,11 +189,14 @@ def _import_gi_module(modname):
# Just inspecting the code can raise gi deprecation
# warnings, so ignore them.
try:
from gi import PyGIDeprecationWarning, PyGIWarning
from gi import ( # pylint:disable=import-error
PyGIDeprecationWarning,
PyGIWarning,
)

warnings.simplefilter("ignore", PyGIDeprecationWarning)
warnings.simplefilter("ignore", PyGIWarning)
except Exception:
except Exception: # pylint:disable=broad-except
pass

__import__(m)
Expand Down Expand Up @@ -242,7 +246,7 @@ def _register_require_version(node):
import gi

gi.require_version(node.args[0].value, node.args[1].value)
except Exception:
except Exception: # pylint:disable=broad-except
pass

return node
Expand Down
1 change: 0 additions & 1 deletion astroid/brain/brain_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import astroid


BUFFERED = {"BufferedWriter", "BufferedReader"}
TextIOWrapper = "TextIOWrapper"
FileIO = "FileIO"
Expand Down
1 change: 0 additions & 1 deletion astroid/brain/brain_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,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/LICENSE

import sys

import astroid
from astroid import exceptions
Expand Down
24 changes: 14 additions & 10 deletions astroid/brain/brain_namedtuple_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@
import keyword
from textwrap import dedent

from astroid import MANAGER, UseInferenceDefault, inference_tip, InferenceError
from astroid import arguments
from astroid import exceptions
from astroid import nodes
from astroid import (
MANAGER,
InferenceError,
UseInferenceDefault,
arguments,
exceptions,
inference_tip,
nodes,
util,
)
from astroid.builder import AstroidBuilder, extract_node
from astroid import util


TYPING_NAMEDTUPLE_BASENAMES = {"NamedTuple", "typing.NamedTuple"}
ENUM_BASE_NAMES = {
Expand All @@ -51,15 +55,15 @@ def _infer_first(node, context):
value = next(node.infer(context=context))
if value is util.Uninferable:
raise UseInferenceDefault()
else:
return value
return value
except StopIteration as exc:
raise InferenceError from exc


def _find_func_form_arguments(node, context):
def _extract_namedtuple_arg_or_keyword(position, key_name=None):

def _extract_namedtuple_arg_or_keyword( # pylint: disable=inconsistent-return-statements
position, key_name=None
):
if len(args) > position:
return _infer_first(args[position], context)
if key_name and key_name in found_keywords:
Expand Down
Loading

0 comments on commit 5bc7d63

Please sign in to comment.