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

Fix unsafe utils.safe_infer #5775

Merged
merged 1 commit into from
Feb 6, 2022
Merged

Conversation

cdce8p
Copy link
Member

@cdce8p cdce8p commented Feb 6, 2022

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

Came across an error while testing Home Assistant. safe_infer here assumes that value is a FunctionDef to be able to access value.args.args. The assumption is never fully checked however. value could also be an <Instance of builtins.function ...> which would cause an AttributeError.

I wasn't able to write a dedicated regression test unfortunately. Home Assistant only managed to break it with some combination of patching a builtin function and custom plugins which import parts of the checked files itself.

The condition was originally added in #5409

* Add additional isinstance check
* Originally added in pylint-dev#5409
@cdce8p cdce8p added the Crash πŸ’₯ A bug that makes pylint crash label Feb 6, 2022
@cdce8p cdce8p added this to the 2.13.0 milestone Feb 6, 2022
@coveralls
Copy link

Pull Request Test Coverage Report for Build 1802774914

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 93.935%

Totals Coverage Status
Change from base Build 1802733185: 0.0%
Covered Lines: 14854
Relevant Lines: 15813

πŸ’› - Coveralls

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch ! home-assistant is in the primer though: https://github.com/PyCQA/pylint/blob/main/tests/primer/packages_to_lint_batch_one.json#L26?, was it only on a branch (not yet merged maybe) ?

@cdce8p
Copy link
Member Author

cdce8p commented Feb 6, 2022

Nice catch ! home-assistant is in the primer though: https://github.com/PyCQA/pylint/blob/main/tests/primer/packages_to_lint_batch_one.json#L26?, was it only on a branch (not yet merged maybe) ?

It was in dev, but only merged a few days ago. The issue was only visible because of a custom plugin and then only if the time module was imported in a certain way. Pretty strange tbh. Might be the reason why it didn't show up in the primer tests. I did check astroid, but that seemed to do what was expected.

In the meantime, a fix for Home Assistant has been merged. So it definitely won't show up in the tests anymore.
home-assistant/core#65911

The fix here is never the less useful. If for nothing else then type safety (and mypy).

@Pierre-Sassoulas Pierre-Sassoulas merged commit 84821cc into pylint-dev:main Feb 6, 2022
@cdce8p cdce8p deleted the fix-safe_infer branch February 6, 2022 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Crash πŸ’₯ A bug that makes pylint crash
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants