Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed false positive of no-member for methods of namedtuples instances #4487

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ modules are added.

Closes #3619

* Fix raising false-positive ``no-member`` on instances' methods where class can be inferred
to be derived from Named Tuples

Closes #4377

* Fix documentation errors in "Block disables" paragraph of User Guide.

* New checker ``unnecessary-dict-index-lookup``. Emitted when iterating over dictionary items
Expand Down
3 changes: 3 additions & 0 deletions doc/whatsnew/2.9.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ Other Changes

* Fix incompatibility with Python 3.6.0 caused by ``typing.Counter`` and ``typing.NoReturn`` usage

* Fix raising false-positive ``no-member`` on instances' methods where class can be inferred
to be derived from Named Tuples

* Allow comma-separated list in ``output-format`` and separate output files for
each specified format. Each output file can be defined after a semicolon for example : ``--output-format=json:myfile.json,colorized``

Expand Down
18 changes: 18 additions & 0 deletions pylint/checkers/typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,24 @@ def _emit_no_member(node, owner, owner_name, ignored_mixins=True, ignored_none=T
# See https://github.com/PyCQA/pylint/issues/4123
return False

if (
isinstance(node.parent, astroid.Call)
and isinstance(owner, astroid.Instance)
and isinstance(owner.parent, astroid.Module)
and isinstance(getattr(owner, "_proxied", None), astroid.ClassDef)
and any(
(
isinstance(b, astroid.Name)
and b.name == "tuple"
and utils.is_builtin_object(utils.safe_infer(b))
)
for b in owner._proxied.bases
)
):
# Avoid false positive on function calls on instances of named tuples
# See https://github.com/PyCQA/pylint/issues/4377
return False

return True


Expand Down
14 changes: 14 additions & 0 deletions tests/functional/m/member/member_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,17 @@ class Animal(Enum):
print(keyy)
for vall in Animal.__members__.values():
print(vall)

# To test false positive no-member after _replace() described in issue #4377
# pylint: disable=invalid-name
from urllib import parse
parsed_url = parse.urlparse("http://www.this-is-weird.com")
sorted_query = parse.urlencode(
sorted(parse.parse_qsl(parsed_url.query),
key=lambda param: param[0])
)
new_parsed_url = parse.ParseResult._replace(parsed_url, query=sorted_query)
new_url = new_parsed_url.geturl() # This should not trigger a warning

new_parsed_url = parsed_url._replace(query=sorted_query)
new_url = new_parsed_url.geturl()