asweigart / pyautogui

A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
BSD 3-Clause "New" or "Revised" License
10.22k stars 1.24k forks source link

move function does not take None #684

Closed arisliang closed 2 years ago

arisliang commented 2 years ago

There's an example usage in readme pyautogui.move(None, 10).

It runs with error in repl:

int() argument must be a string, a bytes-like object or a number, not 'NoneType'

version: '0.9.53' windows 10

JayRizzo commented 2 years ago

Hi @arisliang, I hope you are doing well. Yes, I see this too.

This behaviour changed after 3.10 None values do not behave the same. As you can no longer run int(None). Which throws the [Type Conversion error] (https://docs.python.org/3.10/library/functions.html#int). But it should not as it hasn't even been updated yet in the main documentation. int(None) ""used"" to return Zero, hence why we are seeing this complain.

int(None)
# Traceback (most recent call last):
#  File "<stdin>", line 1, in <module>
# TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

I did some digging around and created a fix for you. if you want to resolve this on your machine as a workaround until this gets resolved do the following.

Update Yourself (Workaround)

Locate your pyautogui init file

in your error you will get the path to the file it is complaining on line 701 of pyautogui.init Copy that path and open the file in your text editor.

THEN: Paste these two lines into your existing pyautogui installed package: (mine is line 701 & 702):

        firstArg = 0 if firstArg is None else firstArg
        secondArg = 0 if secondArg is None else secondArg

It should look like this:

    else:
        firstArg = 0 if firstArg is None else firstArg
        secondArg = 0 if secondArg is None else secondArg
        return Point(int(firstArg), int(secondArg))  # firstArg and secondArg are just x and y number values

You can reference my commit if it helps visually.

  1. Save the file.
  2. Close & Reopen your python terminal or interactive session.
  3. ReOpen it and retry your code OR rerun your file. It should work.
  4. If you break something and forgot what you changed you can revert all changes by running.
pip install pyautogui --upgrade --force

# OR

pip3 install pyautogui --upgrade --force

Found & fixed a Separate Issue

** Now in my search I discovered another odd behaviour that I addressed in #690. and PR691 Separately, but just as an FYI.

Have a Great day!

arisliang commented 2 years ago

Thanks for the fix. I can wait for the next release.