Repository navigation
Conversation
pytest.warns records every warning raised in its block. Since TransformerLensOrg#1907 the coordinate-patch hooks wrap an inner transform annotated with typing.List, and beartype >= 0.22 emits a BeartypeDecorHintPep585DeprecationWarning (a UserWarning subclass) for it under the jaxtyping import hook, so the test saw 5 warnings instead of 1 with an up-to-date beartype. The global filterwarnings ignore does not apply inside pytest.warns.
jlarson4
left a comment
There was a problem hiding this comment.
Just one comment on inline commenting consistency
| with pytest.warns(UserWarning, match=r"2 layer\(s\) x 2 position\(s\)") as record: | ||
| lens.coordinate_patch_hooks(toy_model, 3, 5, layers=[0, 1], positions=[0, 1]) | ||
| assert len(record) == 1 | ||
| # pytest.warns records every warning raised in the block, including beartype's PEP 585 |
There was a problem hiding this comment.
Would you please trim this comment down to a single line if possible?
Providing this level of detail about the specific bear type issue that prompted this fix is asking for the comment to go stale. Once the UserWarning described here is fully deprecated and removed from bear type, the comment is referencing something that no longer exists.
This comment could simply be the following:
# Ensure test only fails due to the warning we are testing
There was a problem hiding this comment.
Good point, trimmed it to your suggested one-liner in b3b8938.
|
Checked exact head |
Description
test_coordinate_patch_hooks_warns_once_naming_layer_and_position_countsfails ondev(177d2cc1) with an up-to-date beartype:Since #1907,
coordinate_patch_hookswraps an innertransform(..., positions: List[int], ...)for each layer. Under the jaxtyping import hook, beartype >= 0.22 (checked 0.22.9 and 0.23.1) emits aBeartypeDecorHintPep585DeprecationWarningfor thattyping.Listhint, and that class is aUserWarningsubclass.pytest.warnsrecords every warning raised in its block regardless of thefilterwarningsignore inpyproject.toml, so with two layers the record holds the cost warning plus four beartype notices. CI does not see this becauseuv.lockpins beartype 0.14.1, butpyproject.tomlallowsbeartype>=0.14.1, so a fresh environment gets 0.23.1.The test now counts only the cost warning (matched on its message), which keeps the "warns once" check intact: injecting a second cost warning into
coordinate_patch_hooksstill makes it fail. No library code changes. If you would rather drop the beartype notices at the source, switching the innertransformhints to builtinlist[int]would be the alternative; happy to do that instead.Checked on
dev177d2cc1, macOS arm64, Python 3.12:tests/unit/tools1093 passed. With beartype 0.22.9,tests/unitbefore the change: 7461 passed, this test the only failure.tests/unit/tools1093 passed.413a38b9~1and fails at413a38b9(Analysis Tools Review & Re-contextualization #1907) with beartype 0.23.1.Type of change
Checklist: