Skip to content

How would I annotate the return type of curses.panel.new_panel? #1775

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

Closed
gossrock opened this issue Dec 5, 2017 · 1 comment
Closed

How would I annotate the return type of curses.panel.new_panel? #1775

gossrock opened this issue Dec 5, 2017 · 1 comment

Comments

@gossrock
Copy link
Contributor

gossrock commented Dec 5, 2017

In looking into what it would take to complete typing for the curses module I see that the following modules do not exist and therefore have not typing info:
curses.ascii
curses.panel
curses.textpad

These all look to be fairly straightforward. But ...

Something that is confusing me is that when you create a panel:
p = curses.panel.new_panel(win)
and check it's type it returns
<class '_curses_panel.curses panel'>

it seems that there is a space in the class name because when I run help(p) I get:

class curses panel(builtins.object)
 |  Methods defined here:
 |
 |  above(...)
 |
...

In my digging brought me to the source code at https://github.com/python/cpython/blob/master/Modules/_curses_panel.c
starting at line 381 we have a referance to 'curses panel'

static PyType_Spec PyCursesPanel_Type_spec = {
    "_curses_panel.curses panel",
    sizeof(PyCursesPanelObject),
    0,
    Py_TPFLAGS_DEFAULT,
    PyCursesPanel_Type_slots
};

My C is only Kindergarten read only and so I have gone well beyond my depth. So how would I annotate the return type of curses.panel.new_panel?

@JelleZijlstra
Copy link
Member

In the stub, you can just define a private class like class _curses_panel, and annotate new_panel as returning _curses_panel. Names starting with _ are purely for private use in the stub, and their actual names don't matter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants