Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Do not allowtype[] to containLiteral types#18276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
sobolevn merged 5 commits intomasterfromissue-18196
Dec 11, 2024
Merged

Conversation

@sobolevn
Copy link
Member

@sobolevnsobolevn commentedDec 10, 2024
edited
Loading

Closes#18196

jorenham reacted with thumbs down emoji
with recursive types like T = Type[T], because internal representation of
TypeType item is normalized (i.e. always a proper type).
Also forbids `Type[Literal[...]]`, because typing spec does not allow it.

Choose a reason for hiding this comment

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

I think it might be better to frame this in terms of whatis allowed. Here are some other things mypy allows that I don't think make sense:https://mypy-play.net/?mypy=latest&python=3.12&gist=aa900cb6c86fd55901b21ee182aa35ec

Copy link
MemberAuthor

@sobolevnsobolevnDec 10, 2024
edited
Loading

Choose a reason for hiding this comment

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

I suspected that this will be brought up :)
I would prefer to keep this PR focused on just one thing. Because, for example, I only agree with the first example:type[TypeGuard[int]], but it is a completely different thing to fix.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I think that we can clarify this inhttps://github.com/python/typing/tree/main/docs/spec

Choose a reason for hiding this comment

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

This is already specified in the grammar athttps://typing.readthedocs.io/en/latest/spec/annotations.html#type-and-annotation-expressions . (Though I noticed we're missing unions there, which should be supported.)

Choose a reason for hiding this comment

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

I'm fine with deferring other similar changes to other PRs, though.

sobolevn reacted with thumbs up emoji
@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

Diff frommypy_primer, showing the effect of this PR on open source code:

bokeh (https://github.com/bokeh/bokeh)+ src/bokeh/core/property/enum.py: note: In function "__init__":+ src/bokeh/core/property/enum.py:64:30: error: type[...] can't contain "Literal[...]"  [valid-type]+ src/bokeh/core/property/enum.py:70:36: error: type[...] can't contain "Literal[...]"  [valid-type]

@sobolevnsobolevn merged commit40730c9 intomasterDec 11, 2024
19 checks passed
@sobolevnsobolevn deleted the issue-18196 branchDecember 11, 2024 08:10
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@JelleZijlstraJelleZijlstraJelleZijlstra left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

type[Literal['']] does not acceptstr as the type

2 participants

@sobolevn@JelleZijlstra

[8]ページ先頭

©2009-2025 Movatter.jp