typeshed icon indicating copy to clipboard operation
typeshed copied to clipboard

pyAutoGui: Correct Return Type of position() to Match Actual Behavior

Open codekoriko opened this issue 1 year ago • 5 comments

Point being a Tuple of float it does not match the actual behavior of the position() function:

def position(x=None, y=None):
    """
    Returns the current xy coordinates of the mouse cursor as a two-integer tuple.

    Args:
      x (int, None, optional) - If not None, this argument overrides the x in
        the return value.
      y (int, None, optional) - If not None, this argument overrides the y in
        the return value.

    Returns:
      (x, y) tuple of the current xy coordinates of the mouse cursor.

    NOTE: The position() function doesn't check for failsafe.
    """
    posx, posy = platformModule._position()
    posx = int(posx)
    posy = int(posy)
    if x is not None:  # If set, the x parameter overrides the return value.
        posx = int(x)
    if y is not None:  # If set, the y parameter overrides the return value.
        posy = int(y)
    return Point(posx, posy)

codekoriko avatar Jan 10 '24 16:01 codekoriko

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

github-actions[bot] avatar Jan 10 '24 16:01 github-actions[bot]

CC @AlexWaygood in case you see any issue with my proposal, but it seems sound to me and my quick testing

(I'm super busy this week unfortunately, so probably won't be able to take a proper look at this until after the 20th, but I trust your judgement!)

AlexWaygood avatar Jan 14 '24 15:01 AlexWaygood

I don't think we're quite ready for PEP 696 in typeshed. Until then, the current annotation is probably best; int is a subtype of float in the type system, after all.

JelleZijlstra avatar Jan 31 '24 04:01 JelleZijlstra

TypeVar defaults are now available in typeshed.

srittau avatar Mar 20 '24 03:03 srittau