Skip to content

Commit

Permalink
Merge 45fed18 into 354e4df
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Sep 18, 2022
2 parents 354e4df + 45fed18 commit 2abfab6
Show file tree
Hide file tree
Showing 20 changed files with 94 additions and 39 deletions.
2 changes: 1 addition & 1 deletion astroid/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def _unpack_args(self, args, context=None):
values.append(arg)
return values

def infer_argument(self, funcnode, name, context):
def infer_argument(self, funcnode, name, context): # noqa: C901
"""infer a function argument value according to the call context
Arguments:
Expand Down
2 changes: 1 addition & 1 deletion astroid/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def implicit_parameters(self) -> Literal[0, 1]:
def is_bound(self):
return True

def _infer_type_new_call(self, caller, context):
def _infer_type_new_call(self, caller, context): # noqa: C901
"""Try to infer what type.__new__(mcs, name, bases, attrs) returns.
In order for such call to be valid, the metaclass needs to be
Expand Down
2 changes: 1 addition & 1 deletion astroid/brain/brain_gi.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
)


def _gi_build_stub(parent):
def _gi_build_stub(parent): # noqa: C901
"""
Inspect the passed module recursively and build stubs for functions,
classes, etc.
Expand Down
50 changes: 45 additions & 5 deletions astroid/brain/brain_mechanize.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,71 +9,111 @@

def mechanize_transform():
return AstroidBuilder(AstroidManager()).string_build(
"""
class Browser(object):
"""class Browser(object):
def __getattr__(self, name):
return None
def __getitem__(self, name):
return None
def __setitem__(self, name, val):
return None
def back(self, n=1):
return None
def clear_history(self):
return None
def click(self, *args, **kwds):
return None
def click_link(self, link=None, **kwds):
return None
def close(self):
return None
def encoding(self):
return None
def find_link(self, text=None, text_regex=None, name=None, name_regex=None, url=None, url_regex=None, tag=None, predicate=None, nr=0):
def find_link(
self,
text=None,
text_regex=None,
name=None,
name_regex=None,
url=None,
url_regex=None,
tag=None,
predicate=None,
nr=0,
):
return None
def follow_link(self, link=None, **kwds):
return None
def forms(self):
return None
def geturl(self):
return None
def global_form(self):
return None
def links(self, **kwds):
return None
def open_local_file(self, filename):
return None
def open(self, url, data=None, timeout=None):
return None
def open_novisit(self, url, data=None, timeout=None):
return None
def open_local_file(self, filename):
return None
def reload(self):
return None
def response(self):
return None
def select_form(self, name=None, predicate=None, nr=None, **attrs):
return None
def set_cookie(self, cookie_string):
return None
def set_handle_referer(self, handle):
return None
def set_header(self, header, value=None):
return None
def set_html(self, html, url="http://example.com/"):
return None
def set_response(self, response):
return None
def set_simple_cookie(self, name, value, domain, path='/'):
def set_simple_cookie(self, name, value, domain, path="/"):
return None
def submit(self, *args, **kwds):
return None
def title(self):
return None
def viewing_html(self):
return None
def visit_response(self, response, request=None):
return None
"""
Expand Down
13 changes: 9 additions & 4 deletions astroid/brain/brain_numpy_core_multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ def vdot(a, b):
return numpy.ndarray([0, 0])""",
"bincount": """def bincount(x, weights=None, minlength=0):
return numpy.ndarray([0, 0])""",
"busday_count": """def busday_count(begindates, enddates, weekmask='1111100', holidays=[], busdaycal=None, out=None):
return numpy.ndarray([0, 0])""",
"busday_offset": """def busday_offset(dates, offsets, roll='raise', weekmask='1111100', holidays=None, busdaycal=None, out=None):
return numpy.ndarray([0, 0])""",
"busday_count": """def busday_count(
begindates, enddates, weekmask='1111100', holidays=[], busdaycal=None, out=None
):
return numpy.ndarray([0, 0])""",
"busday_offset": """def busday_offset(
dates, offsets, roll='raise', weekmask='1111100', holidays=None,
busdaycal=None, out=None
):
return numpy.ndarray([0, 0])""",
"can_cast": """def can_cast(from_, to, casting='safe'):
return True""",
"copyto": """def copyto(dst, src, casting='same_kind', where=True):
Expand Down
7 changes: 4 additions & 3 deletions astroid/brain/brain_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,16 +240,17 @@ def _forbid_class_getitem_access(node: ClassDef) -> None:
def full_raiser(origin_func, attr, *args, **kwargs):
"""
Raises an AttributeInferenceError in case of access to __class_getitem__ method.
Otherwise just call origin_func.
Otherwise, just call origin_func.
"""
if attr == "__class_getitem__":
raise AttributeInferenceError("__class_getitem__ access is not allowed")
return origin_func(attr, *args, **kwargs)

try:
node.getattr("__class_getitem__")
# If we are here, then we are sure to modify object that do have __class_getitem__ method (which origin is one the
# protocol defined in collections module) whereas the typing module consider it should not
# If we are here, then we are sure to modify an object that does have
# __class_getitem__ method (which origin is the protocol defined in
# collections module) whereas the typing module considers it should not.
# We do not want __class_getitem__ to be found in the classdef
partial_raiser = partial(full_raiser, node.getattr)
node.getattr = partial_raiser
Expand Down
5 changes: 3 additions & 2 deletions astroid/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def raise_if_nothing_inferred(func, instance, args, kwargs):
# Expensive decorators only used to emit Deprecation warnings.
# If no other than the default DeprecationWarning are enabled,
# fall back to passthrough implementations.
if util.check_warnings_filter():
if util.check_warnings_filter(): # noqa: C901

def deprecate_default_argument_values(
astroid_version: str = "3.0", **arguments: str
Expand Down Expand Up @@ -208,7 +208,8 @@ def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> _R:
):
warnings.warn(
f"'{arg}' will be a required argument for "
f"'{args[0].__class__.__qualname__}.{func.__name__}' in astroid {astroid_version} "
f"'{args[0].__class__.__qualname__}.{func.__name__}'"
f" in astroid {astroid_version} "
f"('{arg}' should be of type: '{type_annotation}')",
DeprecationWarning,
)
Expand Down
4 changes: 3 additions & 1 deletion astroid/interpreter/_import/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ def find_module(
else:
try:
spec = importlib.util.find_spec(modname)
if spec and spec.loader is importlib.machinery.FrozenImporter: # type: ignore[comparison-overlap]
if (
spec and spec.loader is importlib.machinery.FrozenImporter
): # noqa: E501 # type: ignore[comparison-overlap]
# No need for BuiltinImporter; builtins handled above
return ModuleSpec(
name=modname,
Expand Down
2 changes: 1 addition & 1 deletion astroid/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def _can_load_extension(self, modname: str) -> bool:
modname, self.extension_package_whitelist
)

def ast_from_module_name(
def ast_from_module_name( # noqa: C901
self,
modname: str | None,
context_file: str | None = None,
Expand Down
3 changes: 2 additions & 1 deletion astroid/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
# Please remove astroid/scoped_nodes.py|astroid/node_classes.py in autoflake
# exclude when removing this file.
warnings.warn(
"The 'astroid.node_classes' module is deprecated and will be replaced by 'astroid.nodes' in astroid 3.0.0",
"The 'astroid.node_classes' module is deprecated and will be replaced by "
"'astroid.nodes' in astroid 3.0.0",
DeprecationWarning,
)
2 changes: 1 addition & 1 deletion astroid/nodes/scoped_nodes/scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ def extra_decorators(self) -> list[node_classes.Call]:
return decorators

@cached_property
def type(self) -> str: # pylint: disable=too-many-return-statements
def type(self) -> str: # pylint: disable=too-many-return-statements # noqa: C901
"""The function type for this node.
Possible values are: method, function, staticmethod, classmethod.
Expand Down
4 changes: 3 additions & 1 deletion astroid/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ def name(self):
def qname(self) -> Literal["super"]:
return "super"

def igetattr(self, name: str, context: InferenceContext | None = None):
def igetattr( # noqa: C901
self, name: str, context: InferenceContext | None = None
):
"""Retrieve the inferred values of the given attribute name."""
# '__class__' is a special attribute that should be taken directly
# from the special attributes dict
Expand Down
3 changes: 1 addition & 2 deletions astroid/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ def named_expr_assigned_stmts(


@decorators.yes_if_nothing_inferred
def starred_assigned_stmts(
def starred_assigned_stmts( # noqa: C901
self: nodes.Starred,
node: node_classes.AssignedStmtsPossibleNode = None,
context: InferenceContext | None = None,
Expand Down Expand Up @@ -823,7 +823,6 @@ def _determine_starred_iteration_lookups(
last_lookup = lookup_slice

for element in itered:

# We probably want to infer the potential values *for each* element in an
# iterable, but we can't infer a list of all values, when only a list of
# step values are expected:
Expand Down
5 changes: 3 additions & 2 deletions astroid/rebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def visit_module(
self._reset_end_lineno(newnode)
return newnode

if TYPE_CHECKING:
if TYPE_CHECKING: # noqa: C901

@overload
def visit(self, node: ast.arg, parent: NodeNG) -> nodes.AssignName:
Expand Down Expand Up @@ -1332,7 +1332,8 @@ def visit_attribute(
)
# Prohibit a local save if we are in an ExceptHandler.
if not isinstance(parent, nodes.ExceptHandler):
# mypy doesn't recognize that newnode has to be AssignAttr because it doesn't support ParamSpec
# mypy doesn't recognize that newnode has to be AssignAttr because it
# doesn't support ParamSpec
# See https://github.com/python/mypy/issues/8645
self._delayed_assattr.append(newnode) # type: ignore[arg-type]
else:
Expand Down
3 changes: 2 additions & 1 deletion astroid/scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# Please remove astroid/scoped_nodes.py|astroid/node_classes.py in autoflake
# exclude when removing this file.
warnings.warn(
"The 'astroid.scoped_nodes' module is deprecated and will be replaced by 'astroid.nodes' in astroid 3.0.0",
"The 'astroid.scoped_nodes' module is deprecated and will be replaced by "
"'astroid.nodes' in astroid 3.0.0",
DeprecationWarning,
)
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ extend-ignore =
E203, # Incompatible with black see https://github.com/psf/black/issues/315
W503, # Incompatible with black
B901 # Combine yield and return statements in one function
max-complexity = 83
max-line-length = 138
max-line-length = 110
select = B,C,E,F,W,T4,B9
# Required for flake8-typing-imports (v1.12.0)
# The plugin doesn't yet read the value from pyproject.toml
Expand Down
6 changes: 4 additions & 2 deletions tests/unittest_brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,8 @@ def test_collections_object_not_yet_subscriptable_2(self):

@test_utils.require_version(minver="3.9")
def test_collections_object_subscriptable_3(self):
"""With python39 ByteString class of the colletions module is subscritable (but not the same class from typing module)"""
"""With python39 the ByteString class of the collections module is subscritable
(but not the same class from typing module)"""
right_node = builder.extract_node(
"""
import collections.abc
Expand Down Expand Up @@ -1984,7 +1985,8 @@ class Derived(typing.Hashable, typing.Iterator[int]):
)

def test_typing_object_notsubscriptable_3(self):
"""Until python39 ByteString class of the typing module is not subscritable (whereas it is in the collections module)"""
"""Until python39 ByteString class of the typing module is not
subscriptable (whereas it is in the collections' module)"""
right_node = builder.extract_node(
"""
import typing
Expand Down
8 changes: 5 additions & 3 deletions tests/unittest_brain_ctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

pytestmark = pytest.mark.skipif(
hasattr(sys, "pypy_version_info"),
reason="pypy has its own implementation of _ctypes module which is different from the one of cpython",
reason="pypy has its own implementation of _ctypes module which is different "
"from the one of cpython",
)


Expand Down Expand Up @@ -83,8 +84,9 @@ def test_ctypes_redefined_types_members(c_type, builtin_type, type_code):

def test_cdata_member_access() -> None:
"""
Test that the base members are still accessible. Each redefined ctypes type inherits from _SimpleCData which itself
inherits from _CData. Checks that _CData members are accessibles
Test that the base members are still accessible. Each redefined ctypes type
inherits from _SimpleCData which itself inherits from _CData. Checks that
_CData members are accessible.
"""
src = """
import ctypes
Expand Down
2 changes: 0 additions & 2 deletions tests/unittest_modutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ def test_load_module_set_attribute(self) -> None:

class ExtensionPackageWhitelistTest(unittest.TestCase):
def test_is_module_name_part_of_extension_package_whitelist_true(self) -> None:
"""Test that the is_module_name_part_of_extension_package_whitelist function returns True when needed"""
self.assertTrue(
modutils.is_module_name_part_of_extension_package_whitelist(
"numpy", {"numpy"}
Expand All @@ -429,7 +428,6 @@ def test_is_module_name_part_of_extension_package_whitelist_true(self) -> None:
)

def test_is_module_name_part_of_extension_package_whitelist_success(self) -> None:
"""Test that the is_module_name_part_of_extension_package_whitelist function returns False when needed"""
self.assertFalse(
modutils.is_module_name_part_of_extension_package_whitelist(
"numpy", {"numpy.core"}
Expand Down
7 changes: 4 additions & 3 deletions tests/unittest_nodes_lineno.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,9 +661,10 @@ async def func(): #@
assert isinstance(f1.args.kwonlyargs[0], nodes.AssignName)
assert (f1.args.kwonlyargs[0].lineno, f1.args.kwonlyargs[0].col_offset) == (4, 4)
assert (f1.args.kwonlyargs[0].end_lineno, f1.args.kwonlyargs[0].end_col_offset) == (4, 16)
assert isinstance(f1.args.kwonlyargs_annotations[0], nodes.Name)
assert (f1.args.kwonlyargs_annotations[0].lineno, f1.args.kwonlyargs_annotations[0].col_offset) == (4, 13)
assert (f1.args.kwonlyargs_annotations[0].end_lineno, f1.args.kwonlyargs_annotations[0].end_col_offset) == (4, 16)
annotations = f1.args.kwonlyargs_annotations
assert isinstance(annotations[0], nodes.Name)
assert (annotations[0].lineno, annotations[0].col_offset) == (4, 13)
assert (annotations[0].end_lineno, annotations[0].end_col_offset) == (4, 16)
assert isinstance(f1.args.kw_defaults[0], nodes.Const)
assert (f1.args.kw_defaults[0].lineno, f1.args.kw_defaults[0].col_offset) == (4, 19)
assert (f1.args.kw_defaults[0].end_lineno, f1.args.kw_defaults[0].end_col_offset) == (4, 20)
Expand Down

0 comments on commit 2abfab6

Please sign in to comment.