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

Add slots to dataclasses with Python 3.10+ #9413

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Oct 3, 2024

I'm 50/50 on if we should move this forward as I'm not sure 4.x will be out by the time we drop python 3.9 support and once we do we can add slots=True to all the dataclasses anyways (if we don't forget)

What do these changes do?

Add slots to dataclasses with Python 3.10+. No need to backport as 3.x uses attrs and already has slots here.

This idea comes from https://github.com/esphome/aioesphomeapi/blob/main/aioesphomeapi/model.py where we have a lot of small data classes generated from protobuf messages but still need to support older python.

related issue #4618 (comment)

Are there changes in behavior for the user?

no

Is it a substantial burden for the maintainers to support this?

no

@bdraco
Copy link
Member Author

bdraco commented Oct 3, 2024

3.x already has slots

aiohttp/client.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/client_reqrep.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/client_reqrep.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/client_reqrep.py:@attr.s(auto_attribs=True, slots=True, frozen=True, cache_hash=True)
aiohttp/client_ws.py:@attr.s(frozen=True, slots=True)
aiohttp/helpers.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/helpers.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/helpers.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/tracing.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/tracing.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/tracing.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/tracing.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/tracing.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/tracing.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/tracing.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/tracing.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/tracing.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/tracing.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/tracing.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/tracing.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/tracing.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/tracing.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/tracing.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/tracing.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/web_protocol.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/web_request.py:@attr.s(auto_attribs=True, frozen=True, slots=True)
aiohttp/web_routedef.py:@attr.s(auto_attribs=True, frozen=True, repr=False, slots=True)
aiohttp/web_routedef.py:@attr.s(auto_attribs=True, frozen=True, repr=False, slots=True)
aiohttp/web_ws.py:@attr.s(auto_attribs=True, frozen=True, slots=True)

Copy link

codecov bot commented Oct 3, 2024

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
3333 1 3332 30
View the top 1 failed tests by shortest run time
tests.test_web_functional test_response_context_manager_error[pyloop]
Stack Traces | 0.041s run time
aiohttp_server = <function aiohttp_server.<locals>.go at 0x10729c160>

    #x1B[0m#x1B[94masync#x1B[39;49;00m #x1B[94mdef#x1B[39;49;00m #x1B[92mtest_response_context_manager_error#x1B[39;49;00m(aiohttp_server: AiohttpServer) -> #x1B[94mNone#x1B[39;49;00m:#x1B[90m#x1B[39;49;00m
        #x1B[94masync#x1B[39;49;00m #x1B[94mdef#x1B[39;49;00m #x1B[92mhandler#x1B[39;49;00m(request: web.Request) -> web.Response:#x1B[90m#x1B[39;49;00m
            #x1B[94mreturn#x1B[39;49;00m web.Response(text=#x1B[33m"#x1B[39;49;00m#x1B[33msome text#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m)#x1B[90m#x1B[39;49;00m
    #x1B[90m#x1B[39;49;00m
        app = web.Application()#x1B[90m#x1B[39;49;00m
        app.router.add_route(#x1B[33m"#x1B[39;49;00m#x1B[33mGET#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, #x1B[33m"#x1B[39;49;00m#x1B[33m/#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, handler)#x1B[90m#x1B[39;49;00m
        server = #x1B[94mawait#x1B[39;49;00m aiohttp_server(app)#x1B[90m#x1B[39;49;00m
        session = aiohttp.ClientSession()#x1B[90m#x1B[39;49;00m
        cm = session.get(server.make_url(#x1B[33m"#x1B[39;49;00m#x1B[33m/#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m))#x1B[90m#x1B[39;49;00m
        resp = #x1B[94mawait#x1B[39;49;00m cm#x1B[90m#x1B[39;49;00m
        #x1B[94mwith#x1B[39;49;00m pytest.raises(#x1B[96mRuntimeError#x1B[39;49;00m):#x1B[90m#x1B[39;49;00m
            #x1B[94masync#x1B[39;49;00m #x1B[94mwith#x1B[39;49;00m resp:#x1B[90m#x1B[39;49;00m
                #x1B[94massert#x1B[39;49;00m resp.status == #x1B[94m200#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
                resp.content.set_exception(#x1B[96mRuntimeError#x1B[39;49;00m())#x1B[90m#x1B[39;49;00m
                #x1B[94mawait#x1B[39;49;00m resp.read()#x1B[90m#x1B[39;49;00m
        #x1B[94massert#x1B[39;49;00m resp.closed#x1B[90m#x1B[39;49;00m
    #x1B[90m#x1B[39;49;00m
        #x1B[94massert#x1B[39;49;00m session._connector #x1B[95mis#x1B[39;49;00m #x1B[95mnot#x1B[39;49;00m #x1B[94mNone#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
>       #x1B[94massert#x1B[39;49;00m #x1B[96mlen#x1B[39;49;00m(session._connector._conns) == #x1B[94m1#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
#x1B[1m#x1B[31mE       assert 0 == 1#x1B[0m
#x1B[1m#x1B[31mE        +  where 0 = len({})#x1B[0m
#x1B[1m#x1B[31mE        +    where {} = <aiohttp.connector.TCPConnector object at 0x106f4f160>._conns#x1B[0m
#x1B[1m#x1B[31mE        +      where <aiohttp.connector.TCPConnector object at 0x106f4f160> = <aiohttp.client.ClientSession object at 0x106270440>._connector#x1B[0m

aiohttp_server = <function aiohttp_server.<locals>.go at 0x10729c160>
app        = <Application 0x1072c5930>
cm         = <aiohttp.client._BaseRequestContextManager object at 0x106f4f790>
handler    = <function test_response_context_manager_error.<locals>.handler at 0x10729c280>
resp       = <ClientResponse(http://127.0.0.1:50143/) [200 OK]>
<CIMultiDictProxy('Content-Type': 'text/plain; charset=utf-8', 'Content-Length': '9', 'Date': 'Tue, 08 Oct 2024 13:00:13 GMT', 'Server': 'Python/3.9 aiohttp/4.0.0a2.dev0')>

server     = <aiohttp.test_utils.TestServer object at 0x106f4f340>
session    = <aiohttp.client.ClientSession object at 0x106270440>

#x1B[1m#x1B[31mtests/test_web_functional.py#x1B[0m:1930: AssertionError

To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Oct 4, 2024
@bdraco bdraco added the backport:skip Skip backport bot label Oct 4, 2024
@bdraco bdraco marked this pull request as ready for review October 4, 2024 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip Skip backport bot bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant