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

[ PySimpleGUIWeb ] Python warning #3663

Open
8 tasks
John-Wheater opened this issue Nov 25, 2020 · 5 comments
Open
8 tasks

[ PySimpleGUIWeb ] Python warning #3663

John-Wheater opened this issue Nov 25, 2020 · 5 comments
Labels
Bug Something's not right

Comments

@John-Wheater
Copy link

Type of Issues (Enhancement, Error, Bug, Question)

[ Question] I noticed an important syntax warning in PySimpleGuiWeb.py

Operating System

MacOS Catalina 10.15,3

Python version

3.8

PySimpleGUI Port and Versio

Ports = Web

PySimpleGUIWeb Version: 0.39.0.5

Your Experience Levels In Months or Years

10_______ Python programming experience
20_____ Programming experience overall
yes___ Have used another Python GUI Framework (tkinter, Qt, etc) previously (yes/no is fine)?

You have completed these steps:

  • Read instructions on how to file an Issue
  • Searched through main docs http://www.PySimpleGUI.org for your problem
  • Searched through the readme for your specific port if not PySimpleGUI (Qt, WX, Remi)
  • Looked for Demo Programs that are similar to your goal http://www.PySimpleGUI.com
  • Note that there are also Demo Programs under each port on GitHub
  • Run your program outside of your debugger (from a command line)
  • Searched through Issues (open and closed) to see if already reported
  • Try again by upgrading your PySimpleGUI.py file to use the current one on GitHub. Your problem may have already been fixed but is not yet on PyPI.

Description of Problem / Question / Details

I've got a very simple program that works well with PySimpleGui tkinter, but works only partly in PySimpleGUIWeb.

That's not actually the problem! It's not urgent, but I'll raise it as a new issue sometime maybe. I mention it because I loaded the latest version as a file into my project. It gave no improvement, but when it was compiled, Wing IDE gave the following warnings:

Line 1362: SyntaxWarning: "is not" with a literal. Did you mean "!="?
Line 1368: same
I looked at the code, and it does in fact do the opposite of what you want.
(1362: if image_size is not (None, None):

I notice it's been put right elsewhere, e.g.
(3859: if element.ReturnValues[0] is not None)
although "if not element.ReturnValues[0]" is better,
and maybe
(ParmGiven = parm[0] and parm[1])
and later:
(if not ParmGiven)
would be even better

Code To Duplicate

Paste your code here



### Code To Duplicate

A short program that isolates and demonstrates the problem (i.e. please don't paste a link to your 400 line program.... instead paste your 10 line program in full).  

Yes, it is a pain to narrow down problems, but it's part of the debugging process.  Help me help you by providing something that can be executed so that work on getting you a fix or a workaround can immediately begin.

This pre-formatted code block is all set for you to paste in your bit of code:

```python
import PySimpleGUI as sg

## Paste your code here
@PySimpleGUI
Copy link
Owner

None is special in Python. It is this specialness that is the reason why it's used EVERYWHERE in PySimpleGUI.

There are at least 3 of these special kinds of constants in Python where you are encouraged / instructed to use is rather than == or != and those are: True, False, and None.

I'm surprised Wing would complain about this. I would expect it to warn if a comparison against None was performed using == or !=.

PEP8 explicitly mentions None comparisons.

image

image

They mentioned one instance that you've suggested:

Also, beware of writing if x when you really mean if x is not None

This is exactly the opposite of what you're suggesting


I think you are correct in the primary example of (None, None). The tuple (None, None) is not the same as None. There may be more than one copy of it so I should not have used is with it. I'll make the change to that one as it's a pretty dangerous thing that I did. Thanks for pointing out this one:

if image_size is not (None, None):

It could be a problem and I'll make some tests and the appropriate changes.

But comparisons against None need to be the way they are. I cannot simply say if not x when I want to test for not None because 0 will also be True. This is exactly why I use None. It's so that "0" can be used along with any other value.

@PySimpleGUI PySimpleGUI added Bug Something's not right Done - Install Dev Build (see docs for how) See https://docs.pysimplegui.com/en/latest/documentation/installing_licensing/upgrading/ labels Nov 25, 2020
@PySimpleGUI
Copy link
Owner

OK, all fixed up in 0.39.0.6. Also fixed the type comparisons. I wasn't using isinstance in some, uhm, instances and was comparing directly against the type. Not a good thing, so it was good to get both fixed.

@PySimpleGUI PySimpleGUI removed the Done - Install Dev Build (see docs for how) See https://docs.pysimplegui.com/en/latest/documentation/installing_licensing/upgrading/ label Nov 28, 2020
@PySimpleGUI
Copy link
Owner

Rolled back to 0.39.0.5 due to evidently bad fixes. Will readdress later.

@PySimpleGUI PySimpleGUI changed the title Python warning [ PySimpleGUIWeb ] Python warning Nov 28, 2020
@itsthejoker
Copy link

@PySimpleGUI The reason that if image_size is not (None, None): has a warning is because you're not comparing against None -- you're comparing against a tuple containing two Nones. When you apply is against an object, then you're checking that it's the same object that you're pointing at, not whether the values are the same. See here:

>>> x = (None, None)
>>> y = (None, None)
# they have the same value, so this will return true
>>> x == y
True
# but they're not in the same place in memory, so they are not the same object
>>> x is y
False
# if you link another variable to the same object in memory...
>>> z = x
# ...it will return True for an `is` call.
>>> x is z
True
>>> x == z
True
# To show that, the unique ID of the objects for X and Z are the same, but the ID for Y is
# different -- even though they all have the same value.
>>> id(x)
139760977201088
>>> id(z)
139760977201088
>>> id(y)
139760977202176
>>> 

@John-Wheater
Copy link
Author

John-Wheater commented Dec 1, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something's not right
Projects
None yet
Development

No branches or pull requests

3 participants