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

[mypyc] Support new syntax for generic functions and classes (PEP 695)#17357

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
JukkaL merged 16 commits intomasterfrommypyc-type-var-syntax
Jun 11, 2024

Conversation

@JukkaL
Copy link
Collaborator

Generate an implicitGeneric base class for new-style generic classes. For this to work, also create C statics that can be used to access type variable objects (e.g.T orTs) at runtime. These are needed when evaluating base classes. ImportTypeVar and friends from the_typing C extension instead oftyping, since the latter is pretty slow to import, and we don't want to add a hidden new runtime dependency in case the fulltyping module isn't needed.

Generic functions don't need any changes, since they don't support indexing with a type, and type variable types aren't valid in runtime contexts. Type erasure seems sufficient, especially considering that mypyc doesn't support classes nested within functions. (I'm not 100% sure about this though, and we might need to put function type variables into statics eventually.)

Update builtins test fixtures used in mypyc tests to not defined type variables such asT, since these leak into tests and can produce unexpected or unrealistic results.

Ignore upper bounds and value restrictions. These are only used for type checking. This should only affect introspection of type variables, which isn't properly supported in compiled code anyway.

New type alias syntax is not supported in this PR.

@github-actions
Copy link
Contributor

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

@JukkaLJukkaL merged commit415d49f intomasterJun 11, 2024
@JukkaLJukkaL deleted the mypyc-type-var-syntax branchJune 11, 2024 16:13
JukkaL added a commit that referenced this pull requestJun 17, 2024
The main tricky bit is supporting uses of type alias objects at runtime.Python evaluates values of type aliases lazily, but there's no way to dothis using public APIs, so we directly modify the `TypeAliasType` objectthat is used to represent a type alias at runtime in C. Unfortunately,this is fragile and will need to be updated each time CPython updatesthe internal representation of `TypeAliasType` objects.Wrap the target of the type alias within a lambda expression, so that wecan easily create the lazy compute function in mypyc. This also reflectshow this is implemented in CPython.Improve test stubs to avoid various false positives or confusing errorsin tests when type checking runtime operations on types. This also makessome exisisting tests more realistic.Follow-up to#17357.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@jhancejhancejhance approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@JukkaL@jhance

[8]ページ先頭

©2009-2025 Movatter.jp