Skip to content

doctest should support custom ps1/ps2 prompts #77013

Closed

Description

@skirpichev
BPO 32832
Nosy @tim-one, @rhettinger, @skirpichev, @csabella
PRs
  • bpo-32832: support override of ps1/ps2/output prefix for doctest parser #7141
  • 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/tim-one'
    closed_at = <Date 2019-05-13.03:14:42.890>
    created_at = <Date 2018-02-12.13:49:39.413>
    labels = ['3.8', 'type-feature', 'library']
    title = 'doctest should support custom ps1/ps2 prompts'
    updated_at = <Date 2019-05-13.03:14:42.888>
    user = 'https://github.com/skirpichev'

    bugs.python.org fields:

    activity = <Date 2019-05-13.03:14:42.888>
    actor = 'cheryl.sabella'
    assignee = 'tim.peters'
    closed = True
    closed_date = <Date 2019-05-13.03:14:42.890>
    closer = 'cheryl.sabella'
    components = ['Library (Lib)']
    creation = <Date 2018-02-12.13:49:39.413>
    creator = 'Sergey.Kirpichev'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32832
    keywords = ['patch']
    message_count = 9.0
    messages = ['312053', '317801', '317803', '317805', '317806', '317831', '317869', '317901', '342281']
    nosy_count = 4.0
    nosy_names = ['tim.peters', 'rhettinger', 'Sergey.Kirpichev', 'cheryl.sabella']
    pr_nums = ['7141']
    priority = 'normal'
    resolution = 'rejected'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue32832'
    versions = ['Python 3.8']

    Activity

    1. skirpichev commented on Feb 12, 2018

      skirpichevmannequin
      MannequinAuthor

      The Python stdlib allows override of sys.ps1/ps2 (to make IPython-like dynamic prompts and so on). I believe it would be a good idea to
      support this in doctest too, to cover cases when given application
      uses different from defaults settings for the interpreter.

      Probably, we could add ps1/2 optional arguments for DoctestParser.__init__().

      Some projects already patch doctest module for this, e.g. IPython:
      https://github.com/ipython/ipython/blob/master/IPython/testing/plugin/ipdoctest.py
      It shouldn't be too hard to port this feature.

    2. added
      stdlib
      on Feb 12, 2018
    3. rhettinger commented on May 27, 2018

      @rhettinger
      Contributor

      Tim, what do you say, feature or feature creep, straightforward patch or can of worms?

    4. added
      type-feature
      on May 27, 2018
    5. tim-one commented on May 27, 2018

      @tim-one
      Member

      doctest was intended to deal with the standard CPython terminal shell. I'd like to keep it that way, but recognize that everyone wants to change everything into "a framework" ;-)

      How many other shells are there? As Sergey linked to, IPython already dealt with its shell conventions, and PS1/PS2 differences account for a relatively tiny amount of the 600+ lines of IPython-customization code they'd need anyway. That is, I don't see that this would be of much value to IPython.

      So people who "need" this already figured out how to do this - and there aren't many of them anyway. I'd leave it alone.

    6. skirpichev commented on May 27, 2018

      skirpichevmannequin
      MannequinAuthor

      doctest was intended to deal with the standard CPython terminal shell. I'd like to keep it that way

      The point is: ps1/ps2 customization could be considered as part of the standard shell. If stdlib allow such changes - doctest module should take this into account.

    7. tim-one commented on May 27, 2018

      @tim-one
      Member

      Sergey, I understand that, but I don't care. The only people I've ever seen _use_ this are people writing an entirely different shell interface. They're rare. There's no value in complicating doctest to cater to theoretical use cases that don't exist - to the contrary, that's counterproductive complication.

      As your IPython example showed, their job is harder than just replacing PS1/PS2. See their parse() function. They want to cater both to IPython's PS1/PS2 conventions and to the standard CPython terminal shell PS1/PS2 conventions.

      But they don't cater to _more_ than just those either. Why should they? Same thing here: extra complication for no good reason.

    8. skirpichev commented on May 28, 2018

      skirpichevmannequin
      MannequinAuthor

      are people writing an entirely different shell interface. They're rare.

      Or just using a different shell interface. Or even different defaults for the standard shell...

      And they are not rare. Almost nobody in reality use CPython shell - that's definitely true for scientific applications of Python, data scientists, etc.

      As your IPython example showed, their job is harder than _just_ replacing PS1/PS2.

      Yes, custom shells have much more stuff (In/Out arrays, etc), but changing PS1/PS2 - require very tiny modifications for doctest. And such changes - almost all that usually prevent using standard doctest for testing examples, written for applications, which assume "a different shell interface" (which, I remind, may be just a plain CPython shell with customized ps1/ps2).

    9. tim-one commented on May 28, 2018

      @tim-one
      Member

      You missed my point about IPython: forget "In/Out arrays, etc". What you suggest is inadequate for just changing PS1/PS2 for IPython. Again, read their parse() function. They support more than one set of PS1/PS2 conventions. So the code changes you suggest wouldn't help them. So long as they want to support more than one set, they'd still have to write their own parse() function just to deal with multiple PS1/PS2 conventions.

      For the rest, it's not the number of people using non-CPython shells that's rare, but the number _of_ non-CPython shells. IPython is popular, they already solved their problem, and the patch wouldn't help them anyway. Who would it help?

      I don't take "a plain CPython shell with customized ps1/ps2" seriously because, as I said, after some decades now I still don't know of anyone who does that (granting that newbies sometimes try it, go 'ha! ha! - cool!", and never try it again). If any such people exist, I would oppose changing doctest just for them, because the _point_ of doctest is to help write easily understood tests. Catering to changing shell syntax in random ways opposes that goal - programming is a social activity.

      So, sorry, but I remain opposed. Something that might change my mind: find an author of a widely used alternative Python shell who says this change would allow them to _remove_ their own doctest-PS1/PS2 customization code. That would be a real use case.

    10. skirpichev commented on May 28, 2018

      skirpichevmannequin
      MannequinAuthor

      They support _more than one_ set of PS1/PS2 conventions.

      I saw this, not sure if that's required. IMHO, same effect should be possible by running doctest several times with different conventions.

      Who would it help?

      In principle, any project, that uses some custom shell (i.e. IPython) per default. I believe, "easily understood tests" should start with prompts that users could easily recognise.

      Something that might change my mind: find an author of a widely used alternative Python shell who says this change would allow them to _remove_ their own doctest-PS1/PS2 customization code. That would be a real use case.

      I admit, exactly this use case I can't provide right now.

    11. csabella commented on May 13, 2019

      @csabella
      Contributor

      Thank you for the suggestion, but per the discussion with Tim, I am closing as rejected.

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

    Labels

    3.8 (EOL)stdlibtype-feature

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions