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

Don't use hash to avoid attrs warning #3054

Merged
merged 3 commits into from
Aug 4, 2024

Conversation

CoolCat467
Copy link
Member

@CoolCat467 CoolCat467 commented Aug 3, 2024

Fixes #3053, this pull request replaces all uses of @attrs.define(... hash=x) with @attrs.define(... unsafe_hash=x).
In attrs >= 24.1.0, a warning is raised that hash is going to be removed in August of 2025.
unsafe_hash is an alias for hash as of attrs v22.2.0, so there should be no functional changes.

`unsafe_hash` is an alias for `hash` as of attrs v22.2.0
Copy link

codecov bot commented Aug 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.63%. Comparing base (20f9291) to head (ea68af7).
Report is 176 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3054   +/-   ##
=======================================
  Coverage   99.63%   99.63%           
=======================================
  Files         120      120           
  Lines       17832    17832           
  Branches     3204     3204           
=======================================
  Hits        17767    17767           
  Misses         46       46           
  Partials       19       19           
Files with missing lines Coverage Δ
src/trio/_core/_entry_queue.py 100.00% <100.00%> (ø)
src/trio/_core/_io_epoll.py 100.00% <100.00%> (ø)
src/trio/_core/_local.py 100.00% <100.00%> (ø)
src/trio/_core/_parking_lot.py 100.00% <100.00%> (ø)
src/trio/_core/_run.py 99.38% <100.00%> (ø)
src/trio/_core/_tests/test_instrumentation.py 100.00% <100.00%> (ø)
src/trio/_highlevel_generic.py 100.00% <100.00%> (ø)
src/trio/_sync.py 100.00% <100.00%> (ø)
src/trio/_tests/test_highlevel_serve_listeners.py 100.00% <100.00%> (ø)
src/trio/testing/_sequencer.py 100.00% <100.00%> (ø)

@richardsheridan
Copy link
Contributor

I'm sure none of our code actually needs this argument, we should be using just eq=false or frozen=true to get the behavior we need. These were all put in before attrs was giving clear guidance on the feature.

Surely the tests all pass if you just remove the hash=false text?

@CoolCat467
Copy link
Member Author

Surely the tests all pass if you just remove the hash=false text?

No idea, haven't tested that, but I was trying to avoid changing functionality.

@A5rocks
Copy link
Contributor

A5rocks commented Aug 3, 2024

Yeah given attrs says:

The overarching theme is to never set the @attrs.define(unsafe_hash=X) parameter yourself. Leave it at None which means that attrs will do the right thing for you, depending on the other parameters:

it's probably a good idea to not use the parameter.


And it looks like eq=False implies unsafe_hash=False:

https://github.com/python-attrs/attrs/blob/6d0e01f5e4e68a2eda5a5c2b826aa6961062be52/src/attr/_make.py#L1368

Copy link
Contributor

@A5rocks A5rocks left a comment

Choose a reason for hiding this comment

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

In addition to removing all unsafe_hash=Falses, can you add a newsfragment? You added a tag not to, but I think it's a good thing to talk about for people just reading the changelogs.

EDIT: also, could you bump attrs in the locked test requirements so we can be sure there's no other warnings?

@A5rocks A5rocks removed the skip newsfragment Newsfragment is not required label Aug 4, 2024
@A5rocks A5rocks changed the title Use unsafe_hash instead of hash to avoid attrs warning Don't use hash to avoid attrs warning Aug 4, 2024
Copy link
Member Author

@CoolCat467 CoolCat467 left a comment

Choose a reason for hiding this comment

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

Looks good @A5rocks

@A5rocks
Copy link
Contributor

A5rocks commented Aug 4, 2024

Let's let others check this, I'll only make a release tomorrow anyways.

@CoolCat467
Copy link
Member Author

Yea mostly commenting on the additional changes you made

Copy link
Contributor

@agronholm agronholm left a comment

Choose a reason for hiding this comment

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

LGTM.

@agronholm
Copy link
Contributor

I need this for AnyIO to pass its test suite on 3.13 😃

@A5rocks A5rocks merged commit 8e38a1e into python-trio:main Aug 4, 2024
35 checks passed
@CoolCat467 CoolCat467 deleted the attrs-24.1.0 branch August 4, 2024 17:54
@hynek
Copy link

hynek commented Aug 5, 2024

Whoa, y'all are fast! I ran into the warning in stamina and wanted to reach out to you how obnoxious it is for you and if I should just soft-deprecate it instead.

Looks like you got most of them except (at least)

@attrs.frozen(eq=False, hash=False, slots=False)

A fun fact on the side: attrs's guidance on hashing goes entirely back to @njsmith opening my eyes and causing a big rewrite of that feature within attrs. So the chances are excellent that you don't need the argument at all.

Tangentially, unsafe_hash has been added to attrs already in 22.2.0, so if you want, you can relax that lower pin a bit.

@A5rocks
Copy link
Contributor

A5rocks commented Aug 5, 2024

I ran into the warning in stamina and wanted to reach out to you how obnoxious it is for you and if I should just soft-deprecate it instead.

We've already handled it and it's been fine: it revealed two configuration issues so that's nice! (one is that deprecation warnings get ignored if the module is imported as a plugin first, the other is that one of the CI runs should use test-requirements.txt as a constraints file but doesn't)

@CoolCat467
Copy link
Member Author

Looks like you got most of them except (at least)

@attrs.frozen(eq=False, hash=False, slots=False)

Unfortunate, surprised CI didn't catch that, but this is because when I made this pull request I did git grep attrs.define | grep hash if I remember correctly, so will need to do another pass looking for anything not using attrs.define

@hynek
Copy link

hynek commented Aug 5, 2024

I did grepped later for hash= and found only this one instance so I think you’ll be fine!

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.

Using trio with attrs 24.1.0 raises a warning
5 participants