Skip to content

More private utilities that need to be marked and public api deprecated #3847

Description

@Rowlando13

In types.py

  • convert_type - rename to _convert_type - currently has no top level import
  • FuncParamType - maybe typing thing? - currently has no top level import

In _ ?,

  • consider deprecating 'open_file'

Activity

  1. added theissue type on Sep 6, 2026
  2. changed the issue type fromtoon Sep 6, 2026
  3. changed the issue type fromtoon Sep 6, 2026
  4. deleted a comment from bunnysayzz on Sep 8, 2026
  5. modified the milestones: 8.5.1, 8.6.0 on Sep 8, 2026
  6. sirosen commented on Sep 10, 2026

    @sirosen
    Contributor

    Should open_file and safecall be made private as well?

    I'm looking at adapting pip-tools to handle v8.5.0 this morning, and we have (this all looks weird to me)...

    my_file = click.open_file(filename, "w+b", atomic=True, lazy=True)
    assert my_file is not None
    if isinstance(my_file, click.utils.LazyFile):
        ctx.call_on_close(click.utils.safecall(my_file.close_intelligently))

    I don't see any reason that anyone outside of click should ever use safecall: it's trivial to write it yourself. open_file doesn't seem good to expose if its return type won't be exposed. It's hard to figure out how to use it correctly in this case.

    (We do want close_intelligently() since the target filename could be "-".)

  7. Rowlando13 commented on Sep 12, 2026

    @Rowlando13
    MemberAuthor

    safe call is deprecated. It should issue a deprecation warning. I will have to check on the other.

  8. Rowlando13 commented on Sep 12, 2026

    @Rowlando13
    MemberAuthor

    We will have to look at open_file. It is public on purpose but may need better type annotation or docs.

  9. sirosen commented on Sep 12, 2026

    @sirosen
    Contributor

    I didn't want to suggest too much at first, but maybe we can spec it out with a typing.Protocol? I'm happy to help out if you want to go that route.

    And yeah, I didn't notice that safecall was also warning, since I fixed this "all at once" on my end.

  10. Rowlando13 commented on Sep 12, 2026

    @Rowlando13
    MemberAuthor

    Feel free to open an issue and propose a PR for what you think is best. I am always interested in type hints or docs that make usage clearer.

  11. davidism commented on Sep 18, 2026

    @davidism
    Member

    I feel like open_file should be private, but I haven't looked enough. atomic should be deprecated, if I remember correctly it's not actually atomic and there are better libraries out there for atomic access. lazy is only useful for the File param type when opening a file for writing, and should be invisible to the public API. It shouldn't matter if it's lazy, it should just close silently.

  12. sirosen commented on Sep 18, 2026

    @sirosen
    Contributor

    Aside: I didn't suggest a protocol because I didn't come up with a good name or home for it. Which might be a sign that it's not a great idea.

    I'm not aware of a good, supported library for atomic/transactional writes. So if it becomes private, I'll probably review this old thread (which has lots of good notes and ideas) and roll my own. Which I'm okay with.

    From my perspective:

    • it's weird that open_file is exposed at all; it feels orthogonal to most of the concerns of click (even though it will be a pain for me, I'm in favor of making it private)
    • it's arguable that even implementing lazy=True is outside of what click should be doing

    I'm using LazyFile in a few places today, but I feel like the ideal path is to put together something that's a replacement and can be passed as a param type, but outside of click. Let the core library stay lean and focused.

  13. davidism commented on Sep 18, 2026

    @davidism
    Member

    it feels orthogonal to most of the concerns of click

    Yes, this is a general problem with the pallets libraries exposing so many utilities and customization points. We're trying to clean this up in general. See for example the next Werkzeug 3.2 release, which is a huge wall of deprecations.

  14. davidism commented on Sep 20, 2026

    @davidism
    Member

    The library I was thinking of was atomicwrites, which is archived in favor of os.replace or os.rename. Those are both documented as atomic.

    The simplest answer for lazy is probably to use Path instead of File param types, and handle opening the file yourself when you write. That's probably a lot simpler than all the stuff we have to go through for File anyway.

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

    typingType annotations and stubs

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions