GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — typing docs: Use soft deprecation · Issue #132941 · python/cpython

typing docs: Use soft deprecation #132941

New issue
Copy link
New issue
Copy link
Open
Open
typing docs: Use soft deprecation#132941
Copy link
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirtopic-typing

Description

@JelleZijlstra
JelleZijlstra
opened on Apr 25, 2025
Issue body actions

A while ago we introduced the concept of "soft deprecation" in PEP 387 (https://peps.python.org/pep-0387/#soft-deprecation): for things that we no longer recommend using, but which we aren't planning to remove in the near future.

The typing docs already list four classes of objects that are deprecated without a scheduled removal (https://docs.python.org/3.14/library/typing.html#deprecation-timeline-of-major-features):

  • Pre-PEP-585 generic aliases (e.g. List)
  • Text
  • Hashable and Sized
  • TypeAlias

I'd like to also soft-deprecate the following:

  • Optional (obviated by PEP-604)
  • NoReturn (prefer Never)
  • typing.ForwardRef (deprecated alias for annotationlib.ForwardRef)
  • types.UnionType (deprecated alias for typing.Union)
  • Creating a Union using subscripting (Union[A, B] instead of A | B) (PEP-604)
  • Creating a TypeVar, ParamSpec, or TypeVarTuple using the constructor directly (PEP-695)
  • Directly inheriting from Generic (PEP-695)

None of those will be removable for many years if ever, but I think it's useful to have a clear statement in the docs that the newer syntax is preferred.

Linked PRs

  • gh-132941: Soft deprecate various typing classes #154480
Reacted by Sebastian Rittau, Avasam, Semyon Moroz, Bartosz Sławecki and Brian Schubert

Activity

  1. AlexWaygood
    added
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    topic-typing
    on Apr 25, 2025
  2. github-project-automation
    added this to docs issueson Apr 25, 2025
  3. github-project-automation
    moved this to Todo in docs issueson Apr 25, 2025
  4. AA-Turner commented on Apr 26, 2025

    @AA-Turner
    AA-Turner
    on Apr 26, 2025
    Member
    More actions

    types.UnionType (deprecated alias for typing.Union)

    I had assumed that merging the two types would mean the types name becomes preferred (as it's an interpreter type). I agree it would be useful to clarify which (or both) of the names to use. I've very likely missed prior discussion on this, though!

    A

  5. JelleZijlstra commented on Apr 26, 2025

    @JelleZijlstra
    JelleZijlstra
    on Apr 26, 2025
    MemberAuthor
    More actions

    In general I see types as the place for interpreter types that don't have a better home. Other typing-related interpreter types (TypeVar, ParamSpec, TypeVarTuple, TypeAliasType) also live in typing not types.

    Reacted by Adam Turner
  6. srittau commented on Apr 28, 2025

    @srittau
    srittau
    on Apr 28, 2025
    Contributor
    More actions

    I'm generally in favor, except for blanket deprecating NoReturn. This should stay non-deprecated for return types, similar to what is currently suggested by the Modernizing Superseded Typing Features document (written by me, so not a third opinion). I see no reason to deprecate NoReturn in this case, especially as I find it more readable. I don't have a very strong opinion on this, though.

  7. sobolevn commented on Apr 28, 2025

    @sobolevn
    sobolevn
    on Apr 28, 2025
    Member
    More actions

    I would like to soft deprecate NoReturn, because right now it is easy for me to explain the difference like: "NoReturn is just an old deprecated name for Never". It would be much harder to explain if there are any nuances.

    Reacted by Carl Meyer, Avasam, Brian Schubert and decorator-factory
  8. AlexWaygood commented on Apr 28, 2025

    @AlexWaygood
    AlexWaygood
    on Apr 28, 2025
    Member
    More actions

    I have no strong opinion on NoReturn. To me it reads slightly better than Never in return annotations. But I can also see the arguments that it's better to have only one preferred way of doing things. I also understand the argument that it's confusing to beginners who think that functions which have no return statements in them "never return", not realising that None is a more appropriate annotation for these functions.

    The other proposed soft deprecations all sound reasonable to me. I'm not wild about using the term "soft deprecation" in documentation, as I don't think it's self-evident to users what it means for something to be "soft-deprecated": you almost always need some explanation of what some specific soft deprecation actually means, practically, if you want users to have clarity about what API is good to use and what isn't. (The existing soft deprecations in typing have slightly different policies laid out in the docs to other soft deprecations in the stdlib!)

    But that's just about how we describe the soft deprecations in the docs, not about whether we do them or not.

    Reacted by Shantanu, Avasam, Adam Turner and Brian Schubert
  9. carljm commented on Apr 28, 2025

    @carljm
    carljm
    on Apr 28, 2025
    Member
    More actions

    FWIW I agree with soft-deprecating NoReturn and recommending Never in all cases. I don't think NoReturn has any advantage in readability that justifies two aliases for the same thing.

    Reacted by Jelle Zijlstra, Semyon Moroz, Avasam, Bartosz Sławecki, Brian Schubert and decorator-factory
    Reacted by sobolevn
  10. srittau commented on Jul 22, 2026

    @srittau
    srittau
    on Jul 22, 2026
    Contributor
    More actions

    Linking a few related issues and PRs for posterity:

    • Use Never for return types PyCQA/flake8-pyi#551
    • Migrate from typing.NoReturn to typing.Never typeshed#13891
    • Recommend Never for return types as well typing#2322
  11. cdce8p commented on Aug 3, 2026

    @cdce8p
    cdce8p
    on Aug 3, 2026
    Contributor
    More actions

    While I think that the soft-deprecations are helpful, I'd like to suggest to exclude the explicit constructor calls for TypeVar, etc and inheriting from Generic at least for now. AFAIK PEP 695 is not a full replacement for these. I've come across at least one case which isn't possible to express with 695 due to the automatic variance inference. If the generic isn't referenced in any method but should be invariant, the TypeVar needs to be constructed using the "old" style. An example from Home Assistant: https://github.com/home-assistant/core/blob/2026.7.4/homeassistant/util/hass_dict.pyi#L12

    _T = TypeVar("_T")  # needs to be invariant
    
    class _Key(Generic[_T]):  # noqa: UP046
        """Base class for Hass key types. At runtime delegated to str."""
    
        def __init__(self, value: str, /) -> None: ...
        ...
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

    docsDocumentation in the Doc dirDocumentation in the Doc dirtopic-typing

    Projects

    • docs issues
      Status
      Todo
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.