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 — Deprecate unusual ways of creating empty TypedDicts · Issue #105570 · python/cpython

Deprecate unusual ways of creating empty TypedDicts #105570

New issue
Copy link
New issue
Copy link
Closed
#105780
Closed
Deprecate unusual ways of creating empty TypedDicts#105570
#105780
Copy link
Labels
3.13only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-featureA feature request or enhancementA feature request or enhancement

Description

@AlexWaygood
AlexWaygood
opened on Jun 9, 2023
Issue body actions

Feature or enhancement

I propose that we deprecate the following two ways of creating empty TypedDicts:

from typing import TypedDict

T = TypedDict("T")
T2 = TypedDict("T2", None)

Pitch

Users currently have four distinct options if they want to create an empty TypedDict with no fields:

T = TypedDict("T")
T2 = TypedDict("T2", None)
T3 = TypedDict("T3", {})
class T4(TypedDict): ...

Of these four options, only T3 and T4 are supported by type checkers. typing.TypedDict has been around for a while now, so if T1 and T2 are still unsupported by type checkers, they probably never will be supported.

Deprecating, and eventually removing, the first two ways of constructing empty TypedDicts will allow us to simplify the code at runtime. It will also be less confusing for users. Every way in which the runtime and type checkers differ in behaviour is a potential point of confusion for users; in general, we should work to keep these points of difference to a minimum.

I also don't think these methods of constructing empty TypedDicts are particularly common.

Previous discussion

For very similar reasons, we previously deprecated and removed the keyword-argument syntax for creating TypedDicts. This was deprecated in 3.11, and removed in 3.13:

  • Deprecate keyword args syntax for TypedDict definition #90224
  • Remove kwargs-based TypedDict creation #104786

In retrospect, we should really have deprecated these ways of creating empty TypedDicts at the same time. But there's no way of changing that now.

Linked PRs

  • gh-105570: Deprecate unusual ways of creating empty TypedDicts #105780

Activity

  1. AlexWaygood
    added
    type-featureA feature request or enhancementA feature request or enhancement
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    topic-typing
    3.13only security fixesonly security fixes
    on Jun 9, 2023
  2. sobolevn commented on Jun 10, 2023

    @sobolevn
    sobolevn
    on Jun 10, 2023
    Member
    More actions

    I think that we should keep T4, because this way people might:

    1. Create some base metadata object and use it for inheritance later on
    2. Create literal empty dict: class EmptyDict(TypedDict): ..., which is a valid use-case

    Others are good candidates to be deprecated, I agree.

  3. AlexWaygood commented on Jun 10, 2023

    @AlexWaygood
    AlexWaygood
    on Jun 10, 2023
    MemberAuthor
    More actions

    I think that we should keep T4

    Yes, I agree. I'm proposing we deprecate T1 and T2, but keep T3 and T4. I've edited my original post to clarify that point :)

  4. AlexWaygood
    added a commit that references this issue on Jun 14, 2023

    pythongh-105570: Deprecate unusual ways of creating empty TypedDicts

    480369f
  5. AlexWaygood
    closed this as completedin #105780on Jun 14, 2023
  6. AlexWaygood
    added a commit that references this issue on Jun 14, 2023

    gh-105570: Deprecate unusual ways of creating empty TypedDicts (#105780)

    7b1f0f2
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

    3.13only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      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.