+ 1

How to disable SyntaxWarning in a bit?

I have this syntax warning every time when I run my bit: "file0.py:95: SyntaxWarning: "is" with a literal. Did you mean "=="?" How can I disable it, do not changing my code?

15th Apr 2023, 3:44 PM
LoooooooL
LoooooooL - avatar
16 Respostas
+ 1
LoooooooL nothing can be done. The warning seems to be non-suppressible. Maybe use earlier Python versions? """ msg358775 - (view)Author: Serhiy Storchaka (serhiy.storchaka) *Date: 2019-12-21 18:18It cannot be suppressed by the code in the module caused a warning, because the warning is emitted at compile time. You need to silence it before compiling that module. Once you have compiled it, warning will no longer be emitted. """ https://bugs.python.org/issue34850
17th Apr 2023, 2:26 PM
Bob_Li
Bob_Li - avatar
+ 9
You should probably not ignore this warning. Whatchout for the difference between "is" and "==". you usually get this warning when comparing values with is. x = 24 if x is 24: print("is 24") is: for comparing identity, it's useful for comparing instances ==: for comparing equality, it's useful for comparing values.
15th Apr 2023, 4:07 PM
Apollo-Roboto
Apollo-Roboto - avatar
+ 7
You will not be able to disable it. However you can "hide" it using try/except keywords. This is not recommended though. You can find more on this in python documentation
15th Apr 2023, 4:36 PM
Lamron
Lamron - avatar
+ 5
LoooooooL please share your code
15th Apr 2023, 4:13 PM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar
+ 5
import warnings warnings.simplefilter("ignore") that's all
15th Apr 2023, 5:23 PM
Binx
Binx - avatar
+ 2
Apollo-Roboto Thanks, I know differents between "==" and "is". I just want to disable this warning in output.
15th Apr 2023, 4:15 PM
LoooooooL
LoooooooL - avatar
+ 2
LoooooooL oh right, remove the try/except block of code. Apollo-Roboto is correct. Change ~line 100 to: **if luck == 'SECRET':** Because you need to compare values, not identity
16th Apr 2023, 7:11 AM
Lamron
Lamron - avatar
+ 2
LoooooooL luck is 'SECRET' "I did it on purpose" But why? It is the wrong thing to do, that's why you're getting the warning. You should be using luck=='SECRET' you think they are the same. they are not the same. Explain your idea, I am sure it is very interesting.😁. Snehil But you shouldn't encourage him to shoot himself in the foot.😅
17th Apr 2023, 5:42 AM
Bob_Li
Bob_Li - avatar
+ 2
no. unfortunately.
18th Apr 2023, 10:22 AM
Bob_Li
Bob_Li - avatar
+ 1
Bob_Li I answered him as per requirements, he clearly mentioned that he doesn't want his code to be changed and about 'shooting himself in foot' he will learn something new from what I gave. I'm not encouraging him to ignore warnings
17th Apr 2023, 11:25 AM
Binx
Binx - avatar
+ 1
Snehil 😁 you're right. Sometimes the best way of learning is the hard way.
17th Apr 2023, 12:11 PM
Bob_Li
Bob_Li - avatar
+ 1
Thank you Bob_Li I don't see here in SoloLearn Code Bits the ability to change the python version. Is it possible?
18th Apr 2023, 9:53 AM
LoooooooL
LoooooooL - avatar
+ 1
As a solution I've hided this warning output using this code in last line: print('\n'*32)
18th Apr 2023, 10:48 AM
LoooooooL
LoooooooL - avatar
0
Snehil Lamron Unfortunately, none of this works here in SoloLearn Code Bits. Sakshi Here is my bit: https://code.sololearn.com/c4EB9UvE76nC/ There is a hint in the code that the program can be hacked using a cheat code. But this is a trick, because it will not work. In previous versions of the interpreter, there were no SyntaxWarning error messages. And now, this little prank is immediately issued when the program starts.
16th Apr 2023, 6:32 AM
LoooooooL
LoooooooL - avatar
0
Lamron I don't know if I was able to explain the idea in the last post. I did it on purpose.
16th Apr 2023, 7:25 AM
LoooooooL
LoooooooL - avatar
0
I'll try to explain again. I'm also adding my previous post to keep things consistent. https://code.sololearn.com/c4EB9UvE76nC/ There is a hint in the code speaking that the program can be "hacked" using a "cheat code". But this is a trick, because it will not work. In previous versions of the interpreter, there were no SyntaxWarning error messages. And now, this little prank is immediately issued when the program starts. I want you to understand that we are on an educational platform. The code I write here is also written for educational purposes. In my snippet, I intentionally used "is" instead of "==", in one of the options. If you delve into reading the code and comments, then you can understand why I use this particular literal. With this trick (intentionally created error), I want to demonstrate how "==" differs from "is". But I do it in a hidden, non-obvious way, forcing the reader of the code to figure out for himself why the code does not work in a way that seems obvious. And it's kind of a Easter egg that's hidden in this code. But the output of this error immediately reveals this Easter egg, which spoils all joy. The output of this error is a kind of spoiler which I want to prevent. I hope I explained my idea in sufficient detail :)
17th Apr 2023, 1:19 PM
LoooooooL
LoooooooL - avatar