Skip to content

Simplify Literal specification by removing redundant sections - #2395

Open
Anjor99 wants to merge 2 commits into
python:mainfrom
Anjor99:remove-redundant-literal-sections
Open

Anjor99 wants to merge 2 commits into
python:mainfrom
Anjor99:remove-redundant-literal-sections

Conversation

@Anjor99

@Anjor99 Anjor99 commented Nov 26, 2026

Copy link
Copy Markdown

Summary

Removes redundant sections from the Literal specification to improve clarity and conciseness.

Specifically:

  • Removes the "Illegal parameters for Literal at type check time" section, which duplicates information covered by the legal parameter section.
  • Removes the "Parameters at runtime" section, which describes implementation details that are not necessary in the typing specification.

Related issue

Closes #2355

@python-cla-bot

python-cla-bot Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@jorenham jorenham left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. I'm in favor of cleaning this up, but let's be careful not to throw the baby out with the bathwater.

Comment thread docs/spec/literal.rst
Comment on lines -169 to -170
- The only exceptions to this rule are the unary ``-`` (minus) and unary ``+`` (plus) for ints: types
like ``Literal[-5]`` and ``Literal[+1]`` are *accepted*.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't mentioned anywhere else in the spec, so it should stay (or moved elsewhere)

Comment thread docs/spec/literal.rst
Comment on lines -156 to -157
- Arbitrary expressions like ``Literal[3 + 4]`` or
``Literal["foo".replace("o", "b")]``.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conformance test quotes this, so I'm not sure if getting rid of it like is wise:

# > Arbitrary expressions [are illegal]

Comment thread docs/spec/literal.rst Outdated
Comment on lines 87 to 88

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we indeed decide to remove the entire illegal parameterizations subsection as you propose here, then this should should also be updated

Comment thread docs/spec/literal.rst Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "at type check time" here only makes sense because of the removed runtime subsection

Remove redundant illegal-parameter and runtime sections while preserving restrictions on valid Literal parameters.
@Anjor99

Anjor99 commented Nov 26, 2026

Copy link
Copy Markdown
Author

@jorenham Thanks for the review! I've made the suggested changes and pushed them. Kept the exceptions for unary + and -, along with the restriction on arbitrary expressions, while simplifying the section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spec: PEP leftovers in the spec for literals

2 participants