Skip to content

[mypyc] Handle non extention classes with attribute annotations for forward defined classes #18577

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 3, 2025

Conversation

svalentin
Copy link
Collaborator

This PR makes add_non_ext_class_attr_ann behave the same way standard python handles modules with from __future__ import annotations by using string types. With this we can reference types declared further in the file. But since this will change in future versions of python, let's only do this for forward references, for types that are defined further down in the same module.
This also works with string type annotations.

Fixes mypyc/mypyc#992

This PR makes `add_non_ext_class_attr_ann` behave the same way standard
python handles modules with `from __future__ import annotations` by
using string types. With this we can reference types declared further in
the file. But since this will change in future versions of python, let's
only do this for forward type references.
This also works with string type annotations.

Fixes mypyc/mypyc#992
@svalentin svalentin requested a review from JukkaL January 31, 2025 17:43
Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

LGTM. This may not solve all potential issues with forward references, but it should cover the most common ones users are likely to hit.

@JukkaL JukkaL merged commit c8489a2 into python:master Feb 3, 2025
12 checks passed
@svalentin svalentin deleted the dataclass branch February 3, 2025 11:45
x612skm pushed a commit to x612skm/mypy-dev that referenced this pull request Feb 24, 2025
…orward defined classes (python#18577)

This PR makes `add_non_ext_class_attr_ann` behave the same way standard
python handles modules with `from __future__ import annotations` by
using string types. With this we can reference types declared further in
the file. But since this will change in future versions of python, let's
only do this for forward references, for types that are defined further
down in the same module.
This also works with string type annotations.

Fixes mypyc/mypyc#992
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.

Segmentation fault executing mypyc compiled code with dataclass referencing a class that has not been defined
2 participants