Skip to content

compileall functions do not document or test return values #69954

Closed

Description

@nchammas
mannequin
BPO 25768
Nosy @brettcannon, @nchammas
Files
  • compileall-doc.patch
  • compileall.patch
  • compileall.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/brettcannon'
    closed_at = <Date 2015-12-27.21:18:49.653>
    created_at = <Date 2015-11-29.22:44:15.622>
    labels = ['type-bug', 'docs']
    title = 'compileall functions do not document or test return values'
    updated_at = <Date 2015-12-27.21:18:49.652>
    user = 'https://github.com/nchammas'

    bugs.python.org fields:

    activity = <Date 2015-12-27.21:18:49.652>
    actor = 'brett.cannon'
    assignee = 'brett.cannon'
    closed = True
    closed_date = <Date 2015-12-27.21:18:49.653>
    closer = 'brett.cannon'
    components = ['Documentation']
    creation = <Date 2015-11-29.22:44:15.622>
    creator = 'nchammas'
    dependencies = []
    files = ['41201', '41277', '41364']
    hgrepos = []
    issue_num = 25768
    keywords = ['patch']
    message_count = 19.0
    messages = ['255600', '255653', '255658', '255665', '255666', '255670', '255675', '255677', '255678', '255897', '255984', '256076', '256162', '256248', '256742', '256777', '256778', '257100', '257101']
    nosy_count = 4.0
    nosy_names = ['brett.cannon', 'docs@python', 'python-dev', 'nchammas']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue25768'
    versions = ['Python 3.6']

    Activity

    1. nchammas commented on Nov 29, 2015

      nchammasmannequin
      MannequinAuthor

      I'm using the public functions of Python's built-in compileall module.

      https://docs.python.org/3/library/compileall.html#public-functions

      There doesn't appear to be documentation of what each of these functions returns.

      I figured out, for example, that compileall.compile_file() returns 1 when the file compiles successfully, and 0 if not.

      If this is "official" behavior, it would be good to see it documented so that we can rely on it.

      I'd be happy to submit a patch to fix this if a committer is willing to shepherd a new contributor (me) through the process. Otherwise, this is probably a quick fix for experienced contributors.

    2. added
      docsDocumentation in the Doc dir
      type-bugAn unexpected behavior, bug, or error
      on Nov 29, 2015
    3. brettcannon commented on Dec 1, 2015

      @brettcannon
      Member

      At this point the return values are probably as official as they are going to be since these are such old functions.

      If you want to write a patch, Nicholas, please see https://docs.python.org/devguide/ for instructions on how to do that.

    4. nchammas commented on Dec 1, 2015

      nchammasmannequin
      MannequinAuthor

      Exciting! I'm on it.

    5. nchammas commented on Dec 1, 2015

      nchammasmannequin
      MannequinAuthor

      OK, here's a patch.

      I reviewed the doc style guide [0] but I'm not 100% sure if I'm using the appropriate tense. There are also a couple of lines that go a bit over 80 characters, but the file already had a few of those.

      Am happy to make any adjustments, if necessary.

      [0] https://docs.python.org/devguide/documenting.html#style-guide

    6. nchammas commented on Dec 1, 2015

      nchammasmannequin
      MannequinAuthor

      And I just signed the contributor agreement. (Some banner showed up when I attached the patch to this issue asking me to do so.)

    7. brettcannon commented on Dec 1, 2015

      @brettcannon
      Member

      Thanks, Nicholas! I'll have a look when I have a chance (hopefully no later than Friday).

    8. nchammas commented on Dec 1, 2015

      nchammasmannequin
      MannequinAuthor

      👍 Take your time.

    9. nchammas commented on Dec 1, 2015

      nchammasmannequin
      MannequinAuthor

      Oh derp. It appears this is dup of bpo-24386. Apologies.

    10. nchammas commented on Dec 1, 2015

      nchammasmannequin
      MannequinAuthor

      Whoops, wrong issue. Reopening.

    11. brettcannon commented on Dec 4, 2015

      @brettcannon
      Member

      I just realized there are no tests for this in test_compileall either. Nicholas, do you have any interest in attempting to add tests for the return values before we document them?

    12. changed the title [-]compileall functions do not document return values[/-] [+]compileall functions do not document or test return values[/+] on Dec 4, 2015
    13. nchammas commented on Dec 5, 2015

      nchammasmannequin
      MannequinAuthor

      Absolutely. I'll add a "bad source file" to setUp() [0] and check return values as part of the existing checks in test_compile_files() [1].

      Does that sound like a good plan to you?

      Also, I noticed that compile_path() has no tests. Should I test it as part of test_compile_files() or as part of a different test function?

      [0] https://hg.python.org/cpython/file/tip/Lib/test/test_compileall.py#l14
      [1] https://hg.python.org/cpython/file/tip/Lib/test/test_compileall.py#l57

    14. brettcannon commented on Dec 7, 2015

      @brettcannon
      Member

      Your solution to the problem SGTM. And testing compile_path() can be separate method.

    15. nchammas commented on Dec 9, 2015

      nchammasmannequin
      MannequinAuthor

      I've added the tests as we discussed. A couple of comments:

      • I found it difficult to reuse the existing setUp() code so had to essentially repeat a bunch of very similar code to create "bad" files. Let me know if you think there is a better way to do this.
      • I'm having trouble with the test for compile_path(). Specifically, it doesn't seem to actually use the value for skip_curdir. Do you understand why?
    16. brettcannon commented on Dec 12, 2015

      @brettcannon
      Member

      Do the tests take much longer with all of the added stuff in setUp()/tearDown()? It's just that all of it has to run for all tests. You could make a mixin or put all of it in a method that you selectively call and which registers the proper cleanup method.

      As for skip_curdir, if you look at https://hg.python.org/cpython/file/default/Lib/compileall.py#l188 you will notice it requires the current directory to be on sys.path and I don't see you make any such change to sys.path (and if you do you can use test_importlib.util.import_state to temporarily mutate sys.path (https://hg.python.org/cpython/file/default/Lib/test/test_importlib/util.py#l165).

    17. nchammas commented on Dec 19, 2015

      nchammasmannequin
      MannequinAuthor

      Ah, I see. The setup/teardown stuff runs for each test.

      So this is what I did:

      • Added a method to add a "bad" source file to the source directory. It gets cleaned up with the existing teardown method.
      • Used test_importlib to temporarily mutate sys.path as you recommended.

      I think this is much closer to what we want. Let me know what you think.

      By the way, are there any docs on test_importlib? I couldn't find any.

    18. brettcannon commented on Dec 20, 2015

      @brettcannon
      Member

      The patch LGTM, Nicholas! I'll commit it when I have a chance.

      As for docs on test_importlib, nothing in the tests directory is documented to prevent people from depending on it since all the code in that directory is explicitly meant for testing Python and not general use.

    19. nchammas commented on Dec 20, 2015

      nchammasmannequin
      MannequinAuthor

      Alright, sounds good to me. Thank you for guiding me through the process!

    20. python-dev commented on Dec 27, 2015

      python-devmannequin
      Mannequin

      New changeset 71f071f2e074 by Brett Cannon in branch 'default':
      Issue bpo-25768: Make compileall functions return booleans and document
      https://hg.python.org/cpython/rev/71f071f2e074

    21. brettcannon commented on Dec 27, 2015

      @brettcannon
      Member

      Thanks for the patch, Nicholas! I have added you to Misc/ACKS.

      I did tweak the patch, though, to have the functions return booleans instead of 1 or 0 and thus tweaked the docs to be less specific about the return type as well as the tests only doing assertTrue and assertFalse instead of directly comparing against 1 or 0 (which would have still worked, but I prefer the weaker definition in case the return value changes in the future).

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

    docsDocumentation in the Doc dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions