Skip to content

adding curses.ascii, curses.panel and curses.textpad modules #1792

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

Merged
merged 10 commits into from
Jan 26, 2018
Merged

adding curses.ascii, curses.panel and curses.textpad modules #1792

merged 10 commits into from
Jan 26, 2018

Conversation

gossrock
Copy link
Contributor

adding these three stub files to complete the curses module stubs. Some notes on this in issue #1775.

@gossrock
Copy link
Contributor Author

Any thoughts on why the python 2.7 tests failed when I was only working in python 3?

@JelleZijlstra
Copy link
Member

The "python 2.7" tests are actually tests using pytype, which happens to run in Python 2.7. It seems to be angry because you're referring to stubs for _curses but it can't find any.

@@ -0,0 +1,69 @@
from typing import Sequence, Union, overload

NUL: int = ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the = ... part.

removed '= ...' from variable definitions
@gossrock
Copy link
Contributor Author

gossrock commented Dec 18, 2017

inside of curses/__init__ it has a similar set of code that doesn't fail:

import _curses
from _curses import * # noqa: F403

I've tried multiple ways of emulating __init__'s code but all was fail in panel and textpad.

@gossrock
Copy link
Contributor Author

gossrock commented Dec 18, 2017

Ah, I see now that curses/__init__.pyi is in tests/pytype_blacklist.txt.
Locally I placed curses/panel.pyi and curses/textpad.pyi in the list and I do not get the errors.

Should this be done?

…t.txt

just like curses/__init__.pyi because they all import _curses. (This
may not be the right thing to do)
@JelleZijlstra
Copy link
Member

Yes, that makes sense (if one part of curses is already in the blacklist, it probably won't hurt pytype to add more).

SP: int
DEL: int

controlnames: Sequence[int]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like a List[str] to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, have been a bit fuzzy about when to be more specific and when to be more general ... Then again it could have been because I was just a bit 'fuzzy' in general. Now that you mention it, more specific sounds like the right choice here.


controlnames: Sequence[int]

def isalnum(c: str) -> bool: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all of these also accept int arguments (_ctoi returns ints directly).

def isxdigit(c: str) -> bool: ...
def isctrl(c: str) -> bool: ...
def ismeta(c: str) -> bool: ...
@overload
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could also be done with a TypeVar ranging over int and str. Using overloads is fine too though.


class Textbox:
stripspaces: bool
def __init__(self, w: _CursesWindow) -> None: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing the undocumented insert_before argument (quoting the code: def __init__(self, win, insert_mode=False):).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was just looking at the documentation. Makes sense to look at the source code to.

class Textbox:
stripspaces: bool
def __init__(self, w: _CursesWindow) -> None: ...
def edit(self, validator: Callable[[int], int]) -> str: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The argument is called validate and is both optional and Optional (i.e., it should be validate: Optional[Callable[[int], int]] = ...).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, documentation said edit([validator]) both make sense but source code always wins.

changed controlnames variable to be declared as List[str] instead of Sequence[str]
@overload
def ctrl(c: str) -> str: ...
@overload
def ctrl(c: int) -> str: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this one be int -> int (like other items around)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's correct. thank-you.

fixed flake8 issue related to needing and underscore before a private TypeVar
Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the changes! Here are a few more comments.

def ascii(c: _Ch) -> _Ch: ...
def ctrl(c: _Ch) -> _Ch: ...
def alt(c: _Ch) -> _Ch: ...
def unctrl(c: _Ch) -> str: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just be Union[str, int] instead a typevar, because it doesn't influence the return type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, Starting to understand the TypeVar now.


controlnames: List[int]

def isalnum(c: str) -> bool: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all these is* functions take Union[str, int] (as mentioned in the previous review)

also change unctrl to also take the same. (instead of the inapropriate TypeVar)
@JelleZijlstra JelleZijlstra merged commit 79e0b94 into python:master Jan 26, 2018
rhysparry added a commit to rhysparry/typeshed that referenced this pull request Feb 8, 2018
* python/master: (269 commits)
  allow Optional[float] for asyncio.wait() timeout arg (python#1860)
  Clean up the pytype blacklist. (python#1851)
  filter function: make the callable of the first overload non-optional so that mypy is able to select the second overload for the  case. (python#1855)
  Accept Text in distutils *Version classes (python#1854)
  Add attrs library (python#1838)
  Add type stub for the lzma module (python#1844)
  Add ImportError attributes name, path for Python 3.3+ (python#1849)
  Add 'message' to click.decorators.version_option (python#1845)
  PEP 553 and PEP 564 (python#1846)
  Adding py36 additions to datetime module (python#1848)
  Remove incomplete thrift stubs that cause false positives. (python#1827)
  adding curses.ascii, curses.panel and curses.textpad modules (python#1792)
  Fix requests session hooks type (python#1794)
  Add StringIO.name and BytesIO.name (python#1802)
  Fix werkzeug environ type (python#1831)
  Change the return type of unittest.TestCase.fail() to NoReturn (python#1843)
  _curses.tparm works on bytes, not str (python#1828)
  Refine types for distutils.version (python#1835)
  Add stub for stat.filemode (python#1837)
  modify pytype_test to run from within pytype too, and support python3 (python#1817)
  ...
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

Successfully merging this pull request may close these issues.

3 participants