Skip to content
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

Bugs in curses.ascii predicates #71266

Closed
serhiy-storchaka opened this issue May 21, 2016 · 5 comments
Closed

Bugs in curses.ascii predicates #71266

serhiy-storchaka opened this issue May 21, 2016 · 5 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

BPO 27079
Nosy @Yhg1s, @4kir4, @serhiy-storchaka
Files
  • curses_ascii.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2016-06-18.19:14:55.922>
    created_at = <Date 2016-05-21.20:09:59.924>
    labels = ['type-bug', 'library']
    title = 'Bugs in curses.ascii predicates'
    updated_at = <Date 2016-07-01.16:59:23.201>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2016-07-01.16:59:23.201>
    actor = 'akira'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2016-06-18.19:14:55.922>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2016-05-21.20:09:59.924>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['42931']
    hgrepos = []
    issue_num = 27079
    keywords = ['patch']
    message_count = 5.0
    messages = ['266020', '268825', '269562', '269573', '269679']
    nosy_count = 3.0
    nosy_names = ['twouters', 'akira', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue27079'
    versions = ['Python 2.7', 'Python 3.5', 'Python 3.6']

    @serhiy-storchaka
    Copy link
    Member Author

    Most curses.ascii predicates corresponds C functions declared in <ctype.h>. But there are some differences:

    1. isblank() returns True for space and backspace instead of space and tab.

    2. ispunct() returns True for non-ASCII and control characters.

    3. iscntrl() returns False for '\x7f'. Note that there is different function isctrl().

    These differences look as bugs. Proposed patch fixes them and adds tests for all curses.ascii functions.

    @serhiy-storchaka serhiy-storchaka added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels May 21, 2016
    @serhiy-storchaka serhiy-storchaka self-assigned this Jun 18, 2016
    @serhiy-storchaka
    Copy link
    Member Author

    Committed with wrong commit message (damn two clipboards on X11) in ac8338546ca8, d7b6c07bc713, d03c8d0a6a73.

    @4kir4
    Copy link
    Mannequin

    4kir4 mannequin commented Jun 30, 2016

    There is an overlapping issue from 2010: "curses.ascii.isblank() function is broken. It confuses backspace (BS 0x08) with tab (0x09)" http://bugs.python.org/issue9770

    Your patch fixes it too (it should be closed). Note: the patch does not pass tests from Lib/test/test_curses_ascii.py attached to bpo-9770 (even if the code: if char_class_name in ('cntrl', 'punct') test = unittest.expectedFailure(test) is removed) e.g., iscntrl(-1) should be False but it returns True:

      $ ./python
      >>> import curses.ascii
      >>> curses.ascii.iscntrl(-1) #XXX expected False
      True

    If we ignore negative ints then isblank, ispunct, iscntrl provided in the curses_ascii.patch are ok.

    @serhiy-storchaka
    Copy link
    Member Author

    Since screen.getch() can return -1, it looks reasonable to make curses.ascii predicates to work with negative integers.

    Do you want to open a new issue and write a patch Akira?

    @4kir4
    Copy link
    Mannequin

    4kir4 mannequin commented Jul 1, 2016

    I'm not sure anything should be done (e.g., it is "undefined behavior" to pass a negative value such as CHAR_MIN (if *char* type is signed) to a character classification function in C. Though EOF value (-1 traditionally) should be handled).

    If you want to explore it further; I've enumerated open questions in 2014 (inconsistent TypeError, ord(c) > 0x100, negative ints handling, etc) http://bugs.python.org/issue9770#msg221008

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant