Skip to content
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

Python 3.10 compatibility #716

Closed
frenzymadness opened this issue Nov 13, 2020 · 7 comments · Fixed by #763
Closed

Python 3.10 compatibility #716

frenzymadness opened this issue Nov 13, 2020 · 7 comments · Fixed by #763
Labels
Bug Typing Typing/stub/Mypy/PyRight related bugs.

Comments

@frenzymadness
Copy link
Contributor

Hello.

We have already started testing RPM packages in Fedora with Python 3.10a2 and attrs is currently not compatible.

The problem is caused by the implementation of PEP 563 — type annotations are now stored as strings which cause asserts like this one to fail:

class TestAnnotations:
    """
    Tests for types derived from variable annotations (PEP-526).
    """

    def test_basic_annotations(self):
        """
        Sets the `Attribute.type` attr from basic type annotations.
        """

        @attr.s
        class C:
            x: int = attr.ib()
            y = attr.ib(type=str)
            z = attr.ib()

        assert int is attr.fields(C).x.type

The value stored in attr.fields(C).x.type is a string "int" instead of a class int.

It seems it was discussed before in #424

@Tinche
Copy link
Member

Tinche commented Nov 13, 2020

Do we need to call attr.resolve_types first in the test?

@frenzymadness
Copy link
Contributor Author

Do I understand it correctly that we are waiting for #593 here?

@hynek
Copy link
Member

hynek commented Jan 5, 2021

Yes. :(

@wsanchez wsanchez added Bug Typing Typing/stub/Mypy/PyRight related bugs. labels Jan 28, 2021
@frenzymadness
Copy link
Contributor Author

FTR, when issue 593 is fixed now, I can use attr.resolve_types(C) in the test_basic_annotations and that makes the previously mentioned assert int is attr.fields(C).x.type pass but the last assert in the test:

assert C.__init__.__annotations__ == {
    "x": int,
    "y": str,
    "return": None,
}

still complains about {'x': 'int'} != {'x': <class 'int'>}. I'm not sure how much you want to make the attrs behave the same under Python 3.10. If that's the goal, we should probably keep tests untouched.

@hynek
Copy link
Member

hynek commented Feb 19, 2021

The test needs to be changed to get_type_hints I'm afraid. There's a bunch more stuff breaking that I'm working on rn.

hynek added a commit that referenced this issue Feb 19, 2021
Python 3.10 has string types everywhere and that has unmasked a bunch of
bugs/edge cases in our code.

Especially the hooks code need a resolving helper for string types. I'm leaving
that for a separate PR.

Fixes #716
hynek added a commit that referenced this issue Feb 19, 2021
Python 3.10 has string types everywhere and that has unmasked a bunch of
bugs/edge cases in our code.

Especially the hooks code need a resolving helper for string types. I'm leaving
that for a separate PR.

Fixes #716
hynek added a commit that referenced this issue Feb 22, 2021
Python 3.10 has string types everywhere and that has unmasked a bunch of
bugs/edge cases in our code.

Especially the hooks code need a resolving helper for string types. I'm leaving
that for a separate PR.

Fixes #716
hynek added a commit that referenced this issue Feb 22, 2021
Python 3.10 has string types everywhere and that has unmasked a bunch of
bugs/edge cases in our code.

Especially the hooks code need a resolving helper for string types. I'm leaving
that for a separate PR.

Fixes #716
hynek added a commit that referenced this issue Feb 22, 2021
* Add Python 3.10 support

Python 3.10 has string types everywhere and that has unmasked a bunch of
bugs/edge cases in our code.

Especially the hooks code need a resolving helper for string types. I'm leaving
that for a separate PR.

Fixes #716

* More robust quote handling

* Use resolve_types decorator where possible

* Use a helper for __init__ annotations

* Add test for various ClassVars
@frenzymadness
Copy link
Contributor Author

Great movement. Can we expect a new release soon?

@hynek
Copy link
Member

hynek commented Feb 22, 2021

We/I need to write some narrative docs about new features and this issue uncovered that our hooks system is very hard to use with Python 3.10/string types, so we'll have to write some kind of attr.resolve_type() that can convert "str" to str.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Typing Typing/stub/Mypy/PyRight related bugs.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants