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

Merged
merged 6 commits into from
Nov 19, 2024
Merged

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

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.73%. Comparing base (3e81852) to head (1f14995).
Report is 2 commits behind head on master.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9413      +/-   ##
==========================================
- Coverage   98.73%   98.73%   -0.01%     
==========================================
  Files         121      121              
  Lines       36730    36728       -2     
  Branches     4383     4384       +1     
==========================================
- Hits        36264    36262       -2     
  Misses        314      314              
  Partials      152      152              
Flag Coverage Δ
CI-GHA 98.61% <96.96%> (-0.01%) ⬇️
OS-Linux 98.30% <96.96%> (-0.01%) ⬇️
OS-Windows 96.13% <100.00%> (-0.01%) ⬇️
OS-macOS 97.40% <96.96%> (-0.01%) ⬇️
Py-3.10.11 97.24% <93.93%> (-0.01%) ⬇️
Py-3.10.15 97.84% <93.93%> (-0.01%) ⬇️
Py-3.11.10 97.83% <93.93%> (-0.07%) ⬇️
Py-3.11.9 97.30% <93.93%> (-0.02%) ⬇️
Py-3.12.7 98.36% <93.93%> (-0.02%) ⬇️
Py-3.13.0 98.36% <93.93%> (+<0.01%) ⬆️
Py-3.9.13 97.17% <93.93%> (-0.01%) ⬇️
Py-3.9.20 97.76% <93.93%> (-0.01%) ⬇️
Py-pypy7.3.16 97.32% <93.93%> (-0.02%) ⬇️
VM-macos 97.40% <96.96%> (-0.01%) ⬇️
VM-ubuntu 98.30% <96.96%> (-0.01%) ⬇️
VM-windows 96.13% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@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
Copy link
Member

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

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

Let's roll it out.
When we drop py3.9, we can replace all affected code by a single find+sed command.

Copy link

codspeed-hq bot commented Nov 19, 2024

CodSpeed Performance Report

Merging #9413 will not alter performance

Comparing slots_to_dataclasses (1f14995) with master (3e81852)

Summary

✅ 43 untouched benchmarks

aiohttp/client.py Outdated Show resolved Hide resolved
@bdraco bdraco merged commit 4c3b1c6 into master Nov 19, 2024
40 of 41 checks passed
@bdraco bdraco deleted the slots_to_dataclasses branch November 19, 2024 07:31
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.

2 participants