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

False positive: E1307 Argument 'builtins.NoneType' does not match format type 'd' #2631

Closed
tardyp opened this issue Dec 3, 2018 · 6 comments
Labels
Control flow Requires control flow understanding False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@tardyp
Copy link

tardyp commented Dec 3, 2018

Steps to reproduce

Lint following snippet on python3:

# pylint: disable=C
a = None
if a is not None:
    print("%d" % (a,))

Real life usecase is this code:

https://github.com/buildbot/buildbot/blob/master/master/buildbot/schedulers/forcesched.py#L172
https://github.com/buildbot/buildbot/blob/master/master/buildbot/steps/python_twisted.py#L444

Current behavior

pylint output wrong error:

testpylint.py:5:10: E1307: Argument 'builtins.NoneType' does not match format type 'd' (bad-string-format-type)
buildbot/schedulers/forcesched.py:172 Argument 'builtins.NoneType' does not match format type 'd' [bad-string-format-type]
buildbot/steps/python_twisted.py:444 Argument 'builtins.NoneType' does not match format type 'd' [bad-string-format-type]

Expected behavior

no error

pylint --version output

astroid 2.1.0
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609]

This is a regression from pylint 2.1.1

@tardyp
Copy link
Author

tardyp commented Dec 3, 2018

looks like E1307 was added in 2.2.0 in ba62048

@tardyp
Copy link
Author

tardyp commented Dec 3, 2018

@yugr do you think it is feasible to add a check for None inspection in your checker?

tardyp added a commit to buildbot/buildbot that referenced this issue Dec 3, 2018
@yugr
Copy link
Contributor

yugr commented Dec 4, 2018

Hm, I think the real problem here is not the checking of None per se (it's indeed incorrect to print("%d" % None)) but rather that utils.safe_infer returns NoneType for a. Is there some general approach to fix false positives that require context-specific handling?

@PCManticore PCManticore added Control flow Requires control flow understanding Bug 🪲 labels Dec 4, 2018
@PCManticore
Copy link
Contributor

This is a problem with our control flow inference, which cannot understand the if guard clause. We have a lot of these false positives for other checks as well, all stemming from the fact that our inference engine doesn't understand flow.

@yugr
Copy link
Contributor

yugr commented Dec 4, 2018

@PCManticore Right, I guess there is not much the checker can do then.

@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Bug 🪲 labels Jun 30, 2022
@mbyrnepr2
Copy link
Member

This one no longer reproduces (pylint 2.17.0-dev0 and astroid 2.15.0-dev0) & should be fixed according to pylint-dev/astroid#1189.

@mbyrnepr2 mbyrnepr2 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Control flow Requires control flow understanding False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

5 participants