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

Missing return in abstract property fails in pylint 2.5.0 #3529

Closed
pehala opened this issue Apr 27, 2020 · 1 comment
Closed

Missing return in abstract property fails in pylint 2.5.0 #3529

pehala opened this issue Apr 27, 2020 · 1 comment
Assignees
Labels
Bug 🪲 Crash 💥 A bug that makes pylint crash Regression

Comments

@pehala
Copy link

pehala commented Apr 27, 2020

I have encountered an error when using abstract properties and multiple inheritance. The code itself works in it returns a correct value but it seems that pylint tries to check the abstract property for return which it doesn't have, interestingly the same code without property works with pylint. Adding an empty return statement to C class also fixes this issue.

Steps to reproduce

Sample Code:

from abc import abstractmethod


class A:
   @property
   def test(self):
       return "super"


class C:
   @property
   @abstractmethod
   def test(self):
       "abstract method"


class B(A, C):

   @property
   def test(self):
       try:
           return super().test
       except KeyError:
           x = "x"
           return f"http://%s-production.{x}"

b = B()
print(b.test)

Current behavior

Traceback (most recent call last):
  File "/home/phala/.local/share/virtualenvs/3scale-py-testsuite-FxueJDku/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/home/phala/.local/share/virtualenvs/3scale-py-testsuite-FxueJDku/lib/python3.6/site-packages/pylint/__init__.py", line 22, in run_pylint
    PylintRun(sys.argv[1:])
  File "/home/phala/.local/share/virtualenvs/3scale-py-testsuite-FxueJDku/lib/python3.6/site-packages/pylint/lint/run.py", line 338, in __init__
    linter.check(args)
  File "/home/phala/.local/share/virtualenvs/3scale-py-testsuite-FxueJDku/lib/python3.6/site-packages/pylint/lint/pylinter.py", line 871, in check
    self.get_ast, self._iterate_file_descrs(files_or_modules)
  File "/home/phala/.local/share/virtualenvs/3scale-py-testsuite-FxueJDku/lib/python3.6/site-packages/pylint/lint/pylinter.py", line 904, in _check_files
    self._check_file(get_ast, check_astroid_module, name, filepath, modname)
  File "/home/phala/.local/share/virtualenvs/3scale-py-testsuite-FxueJDku/lib/python3.6/site-packages/pylint/lint/pylinter.py", line 930, in _check_file
    check_astroid_module(ast_node)
  File "/home/phala/.local/share/virtualenvs/3scale-py-testsuite-FxueJDku/lib/python3.6/site-packages/pylint/lint/pylinter.py", line 1063, in check_astroid_module
    ast_node, walker, rawcheckers, tokencheckers
  File "/home/phala/.local/share/virtualenvs/3scale-py-testsuite-FxueJDku/lib/python3.6/site-packages/pylint/lint/pylinter.py", line 1107, in _check_astroid_module
    walker.walk(ast_node)
  File "/home/phala/.local/share/virtualenvs/3scale-py-testsuite-FxueJDku/lib/python3.6/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/home/phala/.local/share/virtualenvs/3scale-py-testsuite-FxueJDku/lib/python3.6/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/home/phala/.local/share/virtualenvs/3scale-py-testsuite-FxueJDku/lib/python3.6/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  [Previous line repeated 2 more times]
  File "/home/phala/.local/share/virtualenvs/3scale-py-testsuite-FxueJDku/lib/python3.6/site-packages/pylint/utils/ast_walker.py", line 72, in walk
    callback(astroid)
  File "/home/phala/.local/share/virtualenvs/3scale-py-testsuite-FxueJDku/lib/python3.6/site-packages/pylint/checkers/typecheck.py", line 958, in visit_attribute
    for n in owner.getattr(node.attrname)
  File "/home/phala/.local/share/virtualenvs/3scale-py-testsuite-FxueJDku/lib/python3.6/site-packages/astroid/objects.py", line 206, in getattr
    return list(self.igetattr(name, context=context))
  File "/home/phala/.local/share/virtualenvs/3scale-py-testsuite-FxueJDku/lib/python3.6/site-packages/astroid/objects.py", line 190, in igetattr
    yield from function.infer_call_result(caller=self, context=context)
  File "/home/phala/.local/share/virtualenvs/3scale-py-testsuite-FxueJDku/lib/python3.6/site-packages/astroid/scoped_nodes.py", line 1714, in infer_call_result
    "The function does not have any return statements"
astroid.exceptions.InferenceError: The function does not have any return statements

Expected behavior

To only report linting errors

pylint --version output

pylint 2.5.0
astroid 2.4.0
Python 3.6.10 (default, Dec 20 2019, 00:00:00) 
[GCC 9.2.1 20190827 (Red Hat 9.2.1-1)]
@pehala pehala changed the title Abstract properties with multiple inheritance fails in pylint 2.5.0 Missing return in abstract property fails in pylint 2.5.0 Apr 27, 2020
@PCManticore PCManticore added Bug 🪲 Crash 💥 A bug that makes pylint crash Regression labels Apr 28, 2020
@PCManticore PCManticore self-assigned this Apr 28, 2020
@PCManticore PCManticore pinned this issue Apr 28, 2020
@GliderGeek
Copy link

GliderGeek commented Apr 28, 2020

I had the same problem with pylint 2.3.0
Fixed it (temporarily) by pinning astroid: astroid==2.3.3

PCManticore added a commit to pylint-dev/astroid that referenced this issue May 1, 2020
…n `Super.getattr()`

``infer_call_result`` can raise InferenceError but we were not handling that when retrieving
objects from the Super instance.

Close pylint-dev/pylint#3529
PCManticore added a commit to pylint-dev/astroid that referenced this issue May 1, 2020
…n `Super.getattr()` (#782)

``infer_call_result`` can raise InferenceError but we were not handling that when retrieving
objects from the Super instance.

Close pylint-dev/pylint#3529
@PCManticore PCManticore unpinned this issue May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Crash 💥 A bug that makes pylint crash Regression
Projects
None yet
Development

No branches or pull requests

3 participants