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 — `get_type_hints` fails for `dataclass` in 3.14 · Issue #144190 · python/cpython

get_type_hints fails for dataclass in 3.14 #144190

New issue
Copy link
New issue
Copy link
Closed
Closed
get_type_hints fails for dataclass in 3.14#144190
Copy link
Labels
3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesdocsDocumentation in the Doc dirDocumentation in the Doc dirtopic-typing

Description

@bfrandeen
bfrandeen
opened on Jan 23, 2026
Issue body actions

Bug report

Bug description:

This code works in 3.13, but fails in 3.14:

from dataclasses import dataclass
from typing import get_type_hints


@dataclass
class MyHintedClass:
    my_attr: int = 1

    def __init__(self):
        self.hints = get_type_hints(self)


my_class = MyHintedClass()
print(my_class.hints)

Failure in 3.14:

~\py\pybug: uv run --python=3.14 python main.py                                                                                                                                                                                                     
Traceback (most recent call last):
  File "C:\Users\bfrandeen\py\pybug\main.py", line 13, in <module>
    my_class = MyHintedClass()
  File "C:\Users\bfrandeen\py\pybug\main.py", line 10, in __init__
    self.hints = get_type_hints(self)
                 ~~~~~~~~~~~~~~^^^^^^
  File "C:\Users\bfrandeen\AppData\Roaming\uv\python\cpython-3.14.2-windows-x86_64-none\Lib\typing.py", line 2401, in get_type_hints
    hints = _lazy_annotationlib.get_annotations(obj, format=format)
  File "C:\Users\bfrandeen\AppData\Roaming\uv\python\cpython-3.14.2-windows-x86_64-none\Lib\annotationlib.py", line 996, in get_annotations
    raise TypeError(f"{obj!r} does not have annotations")
TypeError: MyHintedClass(my_attr=1) does not have annotations

Works in older versions:

~\py\pybug: uv run --python=3.13 python main.py
Using CPython 3.13.2
Removed virtual environment at: .venv
Creating virtual environment at: .venv
Installed 6 packages in 190ms
{'my_attr': <class 'int'>}

CPython versions tested on:

3.14, 3.13

Operating systems tested on:

Windows, Linux

Linked PRs

  • gh-144190: Clarify get_type_hints() instance behavior in docs #144831
  • [3.14] gh-144190: Clarify get_type_hints() instance behavior in docs (GH-144831) #145258

Activity

  1. bfrandeen
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Jan 23, 2026
  2. JelleZijlstra commented on Jan 23, 2026

    @JelleZijlstra
    JelleZijlstra
    on Jan 23, 2026
    Member
    More actions

    Previously get_type_hints() worked on instances by accident; we removed that support because it was not reliable and it was never documented. You should instead use e.g. get_type_hints(type(self)), which will work on all versions.

    I'd be open to adding a note in the docs about this at https://docs.python.org/3.14/library/typing.html#typing.get_type_hints though.

    Reacted by Blair Frandeen, sobolevn and Xuanteng Huang
  3. picnixz
    added
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    topic-typing
    3.14bugs and security fixesbugs and security fixes
    3.15bugs and security fixesbugs and security fixes
    on Jan 23, 2026
  4. github-project-automation
    added this to docs issueson Jan 23, 2026
  5. github-project-automation
    moved this to Todo in docs issueson Jan 23, 2026
  6. picnixz
    removed
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Jan 23, 2026
  7. iamrajhans
    added a commit that references this issue on Feb 15, 2026

    pythongh-144190: Clarify get_type_hints() instance behavior in docs

    1636cce
  8. hugovk
    added a commit that references this issue on Feb 26, 2026

    gh-144190: Clarify get_type_hints() instance behavior in docs (#144831)

    e234662
  9. miss-islington
    added a commit that references this issue on Feb 26, 2026

    pythongh-144190: Clarify get_type_hints() instance behavior in docs (p…

    f0a0e33
  10. hugovk
    closed this as completedon Feb 26, 2026
  11. hugovk
    added a commit that references this issue on Feb 26, 2026

    [3.14] gh-144190: Clarify get_type_hints() instance behavior in docs (G…

    856fdc6
  12. brijkapadia
    added a commit that references this issue on Feb 28, 2026

    pythongh-144190: Clarify get_type_hints() instance behavior in docs (p…

    9577f19
  13. ljfp
    added a commit that references this issue on Apr 25, 2026

    pythongh-144190: Clarify get_type_hints() instance behavior in docs (p…

    70e16e4
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.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesdocsDocumentation 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.