python / python/cpython

class.__annotations__ gives weird value when using built-in type keywords as attribute

Open
#122,937 5 comments 0 reactions 1 assignee View on GitHub

@sobolevn is already working on this.

Since Aug 12, 2024.

docs topic-typing
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:
class some:
    int    : int = 1
    normal : int = 1
some.__annotations__

returns:
{'int': 1, 'normal': 1}

class some:
    int_   : int = 1
    normal : int = 1
some.__annotations__

returns:
{'int_': int, 'normal': int}

CPython versions tested on:

3.11, 3.12

Operating systems tested on:

Linux, Windows

Linked PRs
  • gh-123060

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.