-
-
Notifications
You must be signed in to change notification settings - Fork 275
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
Cannot infer empty functions #485
Comments
Makes sense. This happens because the inference for functions looks through each return value here (https://github.com/PyCQA/astroid/blob/629c92db2dc1b016f4bf47645c95c42e65fd3bd6/astroid/scoped_nodes.py#L1558) and tries to infer the result from there. But since functions like this don't have an explicit return value, the inference gets into |
What should we infer for a function that always raises an exception? I don't think it should be I tried to add this, but It caused a cascade of errors where we are looking for Uninferable instead of const.None |
@brycepg I would say it should return Regarding your last statement, you mean you added |
@PCManticore I made functions that do not have any return/yield nodes infer to |
Ref pylint-dev#485. If the function was inferred (unlike many compiler-builtins) and it contains no Return nodes, then the implicit return value is None.
Ref pylint-dev#485. If the function was inferred (unlike many compiler-builtins) and it contains no Return nodes, then the implicit return value is None.
Ref pylint-dev#485. To avoid additional breakage, we optionally extend is_abstract to consider functions whose body is any raise statement (not just raise NotImplementedError)
…h no returns Squashed commit of the following: commit 7ec6a68 Author: Andrew Haigh <hello@nelf.in> Date: Mon May 3 09:09:17 2021 +1000 Update changelog commit b50a7dd Author: Andrew Haigh <hello@nelf.in> Date: Mon May 3 09:02:29 2021 +1000 Update check of implicit return to ignore abstract methods Ref pylint-dev#485. To avoid additional breakage, we optionally extend is_abstract to consider functions whose body is any raise statement (not just raise NotImplementedError) commit ff719c8 Author: Andrew Haigh <hello@nelf.in> Date: Sat May 1 12:19:52 2021 +1000 Add check of __getitem__ signature to instance_getitem commit 427d422 Author: Andrew Haigh <hello@nelf.in> Date: Sat May 1 11:45:27 2021 +1000 Fix test definition of igetattr recursion and context_manager_inference Ref pylint-dev#663. This test did not actually check for regression of the issue fixed in 55076ca (i.e. it also passed on c87bea1 before the fix was applied). Additionally, it over-specified the behaviour it was attempting to check: whether the value returned from the context manager was Uninferable was not directly relevant to the test, so when this value changed due to unrelated fixes in inference, this test failed. commit 8ec2b47 Author: Andrew Haigh <hello@nelf.in> Date: Sat Apr 24 09:16:16 2021 +1000 Update FunctionDef.infer_call_result to infer None with no Returns Ref pylint-dev#485. If the function was inferred (unlike many compiler-builtins) and it contains no Return nodes, then the implicit return value is None.
Ref pylint-dev#485. If the function was inferred (unlike many compiler-builtins) and it contains no Return nodes, then the implicit return value is None.
Ref pylint-dev#485. To avoid additional breakage, we optionally extend is_abstract to consider functions whose body is any raise statement (not just raise NotImplementedError)
Ref pylint-dev#485. If the function was inferred (unlike many compiler-builtins) and it contains no Return nodes, then the implicit return value is None.
Ref pylint-dev#485. To avoid additional breakage, we optionally extend is_abstract to consider functions whose body is any raise statement (not just raise NotImplementedError)
Ref pylint-dev#485. If the function was inferred (unlike many compiler-builtins) and it contains no Return nodes, then the implicit return value is None.
Ref pylint-dev#485. To avoid additional breakage, we optionally extend is_abstract to consider functions whose body is any raise statement (not just raise NotImplementedError)
* Add regression tests of inference of implicit None return Ref pylint-dev/astroid#485. Depends on pylint-dev/astroid#983. * Update tests to return size from __len__ No reason why they can't when it's relevant, instead of disabling this warning
Steps to reproduce
Current behavior
raises
StopIteration
Expected behavior
Returns
[const.NoneType]
python -c "from astroid import __pkginfo__; print(__pkginfo__.version)"
output2.0.0
This also applies to procedural functions which don't explicitly return any values.
The text was updated successfully, but these errors were encountered: