GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `turtle.teleport` has incorrect-ish signature · Issue #107805 · python/cpython

turtle.teleport has incorrect-ish signature #107805

New issue
Copy link
New issue
Copy link
Closed
Closed
turtle.teleport has incorrect-ish signature#107805
Copy link
Assignees
sobolevn
Labels
3.12only security fixesonly security fixesrelease-blockertopic-tkintertype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@sobolevn
sobolevn
opened on Aug 9, 2023
Issue body actions

Bug report

turtle.teleport added in #103974 seems not quite correct.

Why?

  1. It is produced automagically from Turtle.teleport instance method. It has this signature: def teleport(self, x=None, y=None, *, fill_gap: bool = False) -> None:
  2. The result function turtle.teleport has this signature: def teleport(x, y=None, fill_gap=None)

Notice that it is missing x=None default and for some reason fill_gap is not a kw-only anymore.

The second problem happens because inside it uses inspect.getargs:

cpython/Lib/turtle.py

Line 3927 in 52fbcf6

args, varargs, varkw = inspect.getargs(ob.__code__)
which translates kw-only to positional-or-keyword params.

So, when I try to run turtle.teleport I get:

Traceback (most recent call last):
  File "/Users/sobolev/Desktop/cpython/ex.py", line 60, in <module>
    print(teleport())
          ^^^^^^^^^^
TypeError: teleport() missing 1 required positional argument: 'x'
                     

And with just one arg:

Traceback (most recent call last):
  File "/Users/sobolev/Desktop/cpython/ex.py", line 60, in <module>
    print(teleport(1))
          ^^^^^^^^^^^
  File "<string>", line 4, in teleport
TypeError: Turtle.teleport() takes from 1 to 3 positional arguments but 4 were given
                        

Annotations are also missing. It is not a big problem, but it is inconvenient.

I propose using inspect.signature instead. It will allow us using pos-only and keyword-only params with ease.

I have a PR ready.

Found while working on python/typeshed#10548
CC @AlexWaygood and @terryjreedy

Linked PRs

  • gh-107805: Fix signatures of module-level generated functions in turtle #107807
  • [3.12] gh-107805: Fix signatures of module-level generated functions in turtle (GH-107807) #108749
Reacted by Gregory P. Smith

Activity

  1. sobolevn
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    topic-tkinter
    on Aug 9, 2023
  2. sobolevn
    self-assigned this
    on Aug 9, 2023
  3. sobolevn
    added a commit that references this issue on Aug 9, 2023

    pythongh-107805: Fix signatures of module-level generated functions i…

    40ee61d
  4. terryjreedy commented on Aug 9, 2023

    @terryjreedy
    terryjreedy
    on Aug 9, 2023
    Member
    More actions

    @gpshead merged the PR.

    inspect.getargs it not currently documented, likely because it was replaced by inspect.getfullargspec when keyword-only args were added. The latter was replaced by inspect.signature, but kept for 2.x compatibility for 2.x/3.x code. Turtle should definitely be updated to use inspect.signature.

    Separate issues: I suspect the same would be true of any stdlib code using either getargs or getfullargspec. We should probably deprecate and remove getargs and maybe eventually getfullargspec.

    The getargs call is part of def getmethparlist(ob), which returns a tuple of separate definition and call signatures. Without checking all uses within turtle, I wonder what the point is. For calls that just want the call signature, I wonder if calling getmethodparlist could be replaced by calling signature.

  5. gpshead
    added
    3.12only security fixesonly security fixes
    release-blocker
    on Aug 10, 2023
  6. ezio-melotti
    added this to Release and Deferred blockers 🚫on Aug 10, 2023
  7. github-project-automation
    moved this to Todo in Release and Deferred blockers 🚫on Aug 10, 2023
  8. gpshead commented on Aug 10, 2023

    @gpshead
    gpshead
    on Aug 10, 2023
    Member
    More actions

    FWIW the bug in the PR adding teleport was added by me as I decided fill_gap should be keyword only for a more readable API feel, without realizing that such gross hacks existed elsewhere within turtle that relied on inspect in this manner. yuck! good find.

  9. gpshead
    added a commit that references this issue on Sep 1, 2023

    gh-107805: Fix signatures of module-level generated functions in `tur…

    044b8b3
  10. miss-islington
    added a commit that references this issue on Sep 1, 2023

    pythongh-107805: Fix signatures of module-level generated functions i…

    712dede
  11. Yhg1s
    added a commit that references this issue on Sep 1, 2023

    [3.12] gh-107805: Fix signatures of module-level generated functions …

    5668309
  12. gpshead
    closed this as completedon Sep 2, 2023
  13. github-project-automation
    moved this from Todo to Done in Release and Deferred blockers 🚫on Sep 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @sobolevn
    sobolevn

Labels

3.12only security fixesonly security fixesrelease-blockertopic-tkintertype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

  • Release and Deferred blockers 🚫
    Status
    Done
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.