Skip to content

Make unimported utilities explicitely private #3099

Description

@Rowlando13

This utilities are not imported in init:

  • LazyFile
  • KeepOpenFile
  • make_short_help
  • PacifyFlushWrapper
  • safecall

Is that intentional?

Activity

  1. Rowlando13 commented on Sep 30, 2025

    @Rowlando13
    MemberAuthor
  2. davidism commented on Sep 30, 2025

    @davidism
    Member

    Yes, and in the future I'd lean towards not exposing anything new to the top level (or public) without very deliberate consideration.

  3. Rowlando13 commented on Oct 1, 2025

    @Rowlando13
    MemberAuthor

    I will also add private to the doc strings since they have no leading _.

  4. kdeldycke commented on Oct 8, 2025

    @kdeldycke
    Collaborator

    Maybe we can even move them to the _utils.py file.

  5. Rowlando13 commented on Nov 22, 2025

    @Rowlando13
    MemberAuthor

    I think we should rename them with leading _ and move into _utils if there is not a better spot for them.

  6. kdeldycke commented on Nov 23, 2025

    @kdeldycke
    Collaborator

    Another proposal: if we have a lot of file-related private utilities, we can move them all to an _io.py file. Which can also anticipate a future public facing io.py file.

  7. benblank commented on Dec 15, 2025

    @benblank
    Contributor

    Apologies for butting in, but if LazyFile is being made private, is there a more appropriate type hint for parameters receiving lazily-opened files? In my own CLIs, I'm currently using it in that fashion, e.g.:

    from typing import TYPE_CHECKING
    
    import click
    
    from . import cook_the_data
    
    
    if TYPE_CHECKING:
        from io import BufferedReader
    
        from click.utils import LazyFile
    
    
    @click.command()
    @click.argument("in_file", type=click.File("r"))
    @click.argument("out_file", type=click.File("w"))  # Implicitly lazy.
    def do_stuff(*, in_file: BufferedReader, out_file: LazyFile) -> None:
        raw_data = in_file.read()
        cooked_data = cook_the_data(raw_data)
    
        with out_file.open() as out_file_writer:
            out_file_writer.write(cooked_data)

    It would suck to lose the ability to correctly type-hint out_file, here. 🙂

  8. davidism commented on Dec 15, 2025

    @davidism
    Member

    It should not matter if the file is lazy or not, it has the same interface as a regular file.

  9. benblank commented on Dec 16, 2025

    @benblank
    Contributor

    Okay, I see where my misunderstanding was; I had missed LazyFile.__getattr__ and thought lazy files needed to be explicitly .open()ed before use. Thanks for helping clear that up!

  10. added this to the 8.5.0 milestone on Jul 17, 2026
  11. changed the title [-]Are unimported utilities intentional[/-] [+]Make unimported utilities explicitely private[/+] on Jul 17, 2026
  12. added
    docsUpdates to documentation, readme, docstrings, typos
    typingType annotations and stubs
    on Jul 17, 2026
  13. locked as resolved and limited conversation to collaborators on Aug 1, 2026
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

    docsUpdates to documentation, readme, docstrings, typostypingType annotations and stubs

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions