Skip to content

C/API - Document exceptions #51282

Closed
Closed

Description

@lekma
mannequin
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']

    Activity

    1. lekma commented on Oct 2, 2009

      lekmamannequin
      MannequinAuthor

      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.

    2. added
      interpreter-core
      type-feature
      on Oct 2, 2009
    3. lekma commented on Oct 2, 2009

      lekmamannequin
      MannequinAuthor

      First attempt at implementing this.
      Diff is against trunk.

    4. lekma commented on Oct 2, 2009

      lekmamannequin
      MannequinAuthor

      The same against py3k

    5. birkenfeld commented on Oct 3, 2009

      @birkenfeld
      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.
    6. lekma commented on Oct 4, 2009

      lekmamannequin
      MannequinAuthor

      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 :).

    7. lekma commented on Oct 4, 2009

      lekmamannequin
      MannequinAuthor

      Same as previous against py3k

    8. lekma commented on Dec 20, 2009

      lekmamannequin
      MannequinAuthor

      Is there any chance that this will make it in?

    9. bitdancer commented on Dec 20, 2009

      @bitdancer
      Member

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

    10. pitrou commented on Dec 20, 2009

      @pitrou
      Member

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

      So do I.

    11. bitdancer commented on Dec 20, 2009

      @bitdancer
      Member

      Also, what about tests?

    12. birkenfeld commented on Dec 20, 2009

      @birkenfeld
      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.

    13. bitdancer commented on Dec 20, 2009

      @bitdancer
      Member

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

    14. pitrou commented on Dec 20, 2009

      @pitrou
      Member

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

    15. lekma commented on Dec 21, 2009

      lekmamannequin
      MannequinAuthor

      patch against trunk:

      • fix tabs issue (I hope)
      • add test
    16. lekma commented on Dec 21, 2009

      lekmamannequin
      MannequinAuthor

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

    17. birkenfeld commented on Dec 28, 2009

      @birkenfeld
      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.

    18. lekma commented on Dec 28, 2009

      lekmamannequin
      MannequinAuthor

      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!

    19. birkenfeld commented on Dec 29, 2009

      @birkenfeld
      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.

    20. lekma commented on Dec 30, 2009

      lekmamannequin
      MannequinAuthor

      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).

    21. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      interpreter-coretype-feature

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions