Skip to content

Mark more things as literals - #20604

Open
A5rocks wants to merge 6 commits into
python:masterfrom
A5rocks:more-literals
Open

Mark more things as literals#20604
A5rocks wants to merge 6 commits into
python:masterfrom
A5rocks:more-literals

Conversation

@A5rocks

Copy link
Copy Markdown
Collaborator

Followup to #20492. This is basically just refactoring based on what seems more correct.

@github-actions

This comment has been minimized.

Comment threadmypy/literals.py Outdated
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@JukkaLJukkaL 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.

Does this have any behavior change? If yes, consider adding a test case.

Comment threadmypy/literals.py
Comment threadmypy/literals.py
if e.fullname in LITERAL_NAMES:
return LITERAL_YES
elif isinstance(e.node, TypeAlias) and not e.node.python_3_12_type_alias:
if is_named_instance(e.node.target, LITERAL_NAMES):

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.

Can a type alias refer to anything but None out of the options here? If this is case, maybe avoid LITERAL_NAMES.

@A5rocksA5rocksJan 31, 2026

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I basically just copied over previous code to prevent changes in behavior, but I don't think this can actually happen. (this is here because refers_to_fullname calls is_named_instance and is used in e.g. is_true_literal)

@A5rocks

Copy link
Copy Markdown
CollaboratorAuthor

Does this have any behavior change? If yes, consider adding a test case.

Probably, but I'm unable to construct an example which gets a change of behavior... (i.e. this makes None and NotImplemented aliases into literals now, but using those doesn't seem to actually change anything?)

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for freeto 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.

3 participants

@A5rocks@JukkaL@cdce8p