HypothesisWorks / hypothesis

Hypothesis is a powerful, flexible, and easy to use library for property-based testing.
https://hypothesis.works
Other
7.53k stars 586 forks source link

Python 3.14: StructuralCoverageTag.__init__() takes 1 positional argument but 2 were given #4067

Closed nedbat closed 1 month ago

nedbat commented 1 month ago

The coverage.py nightly Python test runs started failing on Python 3.14:

      def structural_coverage(label: int) -> StructuralCoverageTag:
          try:
              return STRUCTURAL_COVERAGE_CACHE[label]
          except KeyError:
  >           return STRUCTURAL_COVERAGE_CACHE.setdefault(label, StructuralCoverageTag(label))
  E           TypeError: StructuralCoverageTag.__init__() takes 1 positional argument but 2 were given

The other Python versions are fine.

nedbat commented 1 month ago

Note: the deadsnakes nightly 3.14 that I've been using had been broken for a few weeks, so if this is a bug in 3.14, it could have been introduced since July 11th.

hynek commented 1 month ago

The breakage seems to be related to attrs 24.1.0 release.

Based on https://github.com/python-attrs/attrs/issues/1326#issuecomment-2268700397 I would guess that removing the dataclass_transform should fix it??

Zac-HD commented 1 month ago

Thanks to both of you for the report and suggestions! I'm looking into this now and should have a fix out soon.

I'm somewhat surprised that this hasn't failed in our CI yet - we're running 3.14-dev, which pyenv is currently building from cpython main. no, this is obvious, we're currently pinned to the prior version of attrs.

I also don't see how our noop decorator could have some runtime effect: https://github.com/HypothesisWorks/hypothesis/blob/3c15b34ece30825ed153a0b350f5847efb30dd79/hypothesis-python/src/hypothesis/internal/conjecture/data.py#L71-L85

Zac-HD commented 1 month ago

yeah, that's more like it: image

(ok, with a repro in hand it's time to fix this!)

hynek commented 1 month ago

it's beautiful 🥲

Zac-HD commented 1 month ago

https://github.com/HypothesisWorks/hypothesis/pull/4069/commits/cd8a71e35431d980736ff047bde6dba9099a5099 seems to have fixed it, so my best guess is that it's (probably something in combination with) auto_attribs=True and you might be able to repro from that?

It's after midnight here though, so I'm just going to get the fix released and then go to bed 😅

hynek commented 1 month ago

Yes, I've finally managed to compile Python 3.14 on my Mac and apparently attrs can't find annotation-only fields on 3.14 anymore. You don't have to do anything, I've got a lead, I just want to understand better what's happening.

Zac-HD commented 1 month ago

Ah, there's some other updates I wanted anyway in that PR, so might as well ship it 🙂

hynek commented 1 month ago

24.2.0 is out now, so you should be able to replace the whole thing with a single @attr.frozen or even @attrs.frozen since you depend on 22+ anyways.