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

C/API - Document exceptions #51282

Closed
lekma mannequin opened this issue Oct 2, 2009 · 19 comments
Closed

C/API - Document exceptions #51282

lekma mannequin opened this issue Oct 2, 2009 · 19 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@lekma
Copy link
Mannequin

lekma mannequin commented Oct 2, 2009

BPO 7033
Nosy @birkenfeld, @pitrou, @bitdancer, @lekma
Files
  • issue7033_trunk.diff
  • issue7033_py3k.diff
  • issue7033_trunk_2.diff
  • issue7033_py3k_2.diff
  • issue7033_trunk_3.diff
  • issue7033_trunk_3_alt_test.diff
  • 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 = None
    closed_at = <Date 2009-12-28.08:36:09.925>
    created_at = <Date 2009-10-02.11:14:29.034>
    labels = ['interpreter-core', 'type-feature']
    title = 'C/API - Document exceptions'
    updated_at = <Date 2009-12-30.07:26:45.211>
    user = 'https://github.com/lekma'

    bugs.python.org fields:

    activity = <Date 2009-12-30.07:26:45.211>
    actor = 'lekma'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-12-28.08:36:09.925>
    closer = 'georg.brandl'
    components = ['Interpreter Core']
    creation = <Date 2009-10-02.11:14:29.034>
    creator = 'lekma'
    dependencies = []
    files = ['15021', '15022', '15035', '15036', '15645', '15646']
    hgrepos = []
    issue_num = 7033
    keywords = ['patch']
    message_count = 19.0
    messages = ['93439', '93448', '93449', '93484', '93526', '93527', '96667', '96675', '96676', '96677', '96679', '96680', '96682', '96740', '96741', '96943', '96946', '97009', '97022']
    nosy_count = 4.0
    nosy_names = ['georg.brandl', 'pitrou', 'r.david.murray', 'lekma']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue7033'
    versions = ['Python 2.7', 'Python 3.2']

    @lekma
    Copy link
    Mannequin Author

    lekma mannequin commented Oct 2, 2009

    It would be nice to have an obvious/simple way to document C exceptions
    (especially when using the autoexception feature from Sphinx).

    Something along:

    PyObject *PyErr_Create(char *name, const char *doc)
    Creates and returns a new exception object.
    This behaves like PyErr_Create2() with base set to NULL.

    PyObject *PyErr_Create2(char *name, const char *doc, PyObject *base)
    Creates and returns a new exception object.
    The name argument must be the name of the new exception, a C string
    of the form module.class.
    If doc is non-NULL, it will be used to define the docstring for the
    exception.
    if base is NULL, it creates a class object derived from Exception
    (accessible in C as PyExc_Exception).

    for py3k the signatures would be:
    PyObject *PyErr_Create(const char *name, const char *doc)
    PyObject *PyErr_Create2(const char *name, const char *doc, PyObject *base)

    Internally, these functions would pass a dict to PyErr_NewException with
    the key '__doc__' set to doc.

    If there is support for this, I can provide patches for trunk and py3k.

    @lekma lekma mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Oct 2, 2009
    @lekma
    Copy link
    Mannequin Author

    lekma mannequin commented Oct 2, 2009

    First attempt at implementing this.
    Diff is against trunk.

    @lekma
    Copy link
    Mannequin Author

    lekma mannequin commented Oct 2, 2009

    The same against py3k

    @birkenfeld
    Copy link
    Member

    Sounds like a useful new API. Two comments:

    • The version without *base* is not needed. Passing an explicit NULL
      for *base* is easy enough.
    • The name "PyErr_Create" is needlessly different from
      "PyErr_NewException". Something like "PyErr_NewExceptionWithDoc" is better.

    @lekma
    Copy link
    Mannequin Author

    lekma mannequin commented Oct 4, 2009

    Even though I don't fully agree with your comments here is a second
    attempt addressing them, against trunk.

    For the record, I think that the signature difference is enough to
    warrant a name that is a clear cut from PyErr_NewException.
    And in the spirit of the Py_InitModule and PyModule_Create families of
    function I thought the most common/simple form should stand out from the
    more complete one.

    But, hey, I'm happy if this gets in (in any form :).

    @lekma
    Copy link
    Mannequin Author

    lekma mannequin commented Oct 4, 2009

    Same as previous against py3k

    @lekma
    Copy link
    Mannequin Author

    lekma mannequin commented Dec 20, 2009

    Is there any chance that this will make it in?

    @bitdancer
    Copy link
    Member

    Since it's a new CAPI I think it should probably be discussed briefly on
    python-dev.

    @pitrou
    Copy link
    Member

    pitrou commented Dec 20, 2009

    Since it's a new CAPI I think it should probably be discussed briefly on
    python-dev.

    So do I.

    @bitdancer
    Copy link
    Member

    Also, what about tests?

    @birkenfeld
    Copy link
    Member

    Funnily, I already did ask on python-dev, and only got one (+1) answer
    from Brett. I was going to add it some time when I have more cycles for
    Python.

    @bitdancer
    Copy link
    Member

    Yes, I'd say that counts as a brief discussion :)

    @pitrou
    Copy link
    Member

    pitrou commented Dec 20, 2009

    One nitpick: Python/errors.c uses tabs for indentation, your patch
    should as well.

    @lekma
    Copy link
    Mannequin Author

    lekma mannequin commented Dec 21, 2009

    patch against trunk:

    • fix tabs issue (I hope)
    • add test

    @lekma
    Copy link
    Mannequin Author

    lekma mannequin commented Dec 21, 2009

    The same with a simpler test.
    I leave it up to you guys to choose which one is the best.

    @birkenfeld
    Copy link
    Member

    Thanks for the patch! I rewrote the C function a bit to also take a dict
    argument, and added a test for that. Committed in r77088. Will merge
    to py3k.

    @lekma
    Copy link
    Mannequin Author

    lekma mannequin commented Dec 28, 2009

    Thanks for the patch! I rewrote the C function a bit to also take a dict
    argument, and added a test for that. Committed in r77088. Will merge
    to py3k.

    Great!
    Thanks to all for the help!

    @birkenfeld
    Copy link
    Member

    lekma, this patch is now listed in the 2.7 "what's new" document as
    contributed by "the lekma user", please tell us if you want your name there.

    @lekma
    Copy link
    Mannequin Author

    lekma mannequin commented Dec 30, 2009

    lekma, this patch is now listed in the 2.7 "what's new" document as
    contributed by "the lekma user", please tell us if you want your name
    there.

    Nope, that's ok (it's perfect).

    @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
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants