aiohttp icon indicating copy to clipboard operation
aiohttp copied to clipboard

Add slots to dataclasses with Python 3.10+

Open bdraco opened this issue 1 year ago • 2 comments

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 https://github.com/aio-libs/aiohttp/issues/4618#issuecomment-2391231128

Are there changes in behavior for the user?

no

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

no

bdraco avatar Oct 03 '24 23:10 bdraco

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)

bdraco avatar Oct 03 '24 23:10 bdraco

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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

:white_check_mark: 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%) :arrow_down:
OS-Linux 98.30% <96.96%> (-0.01%) :arrow_down:
OS-Windows 96.13% <100.00%> (-0.01%) :arrow_down:
OS-macOS 97.40% <96.96%> (-0.01%) :arrow_down:
Py-3.10.11 97.24% <93.93%> (-0.01%) :arrow_down:
Py-3.10.15 97.84% <93.93%> (-0.01%) :arrow_down:
Py-3.11.10 97.83% <93.93%> (-0.07%) :arrow_down:
Py-3.11.9 97.30% <93.93%> (-0.02%) :arrow_down:
Py-3.12.7 98.36% <93.93%> (-0.02%) :arrow_down:
Py-3.13.0 98.36% <93.93%> (+<0.01%) :arrow_up:
Py-3.9.13 97.17% <93.93%> (-0.01%) :arrow_down:
Py-3.9.20 97.76% <93.93%> (-0.01%) :arrow_down:
Py-pypy7.3.16 97.32% <93.93%> (-0.02%) :arrow_down:
VM-macos 97.40% <96.96%> (-0.01%) :arrow_down:
VM-ubuntu 98.30% <96.96%> (-0.01%) :arrow_down:
VM-windows 96.13% <100.00%> (-0.01%) :arrow_down:

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Oct 03 '24 23:10 codecov[bot]

CodSpeed Performance Report

Merging #9413 will not alter performance

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

Summary

✅ 43 untouched benchmarks

codspeed-hq[bot] avatar Nov 19 '24 07:11 codspeed-hq[bot]