Skip to content

Added beartype package#484

Open
jolaf wants to merge 4 commits intopyodide:mainfrom
jolaf:beartype
Open

Added beartype package#484
jolaf wants to merge 4 commits intopyodide:mainfrom
jolaf:beartype

Conversation

@jolaf
Copy link
Copy Markdown

@jolaf jolaf commented Jan 21, 2026

No description provided.

@jolaf
Copy link
Copy Markdown
Author

jolaf commented Jan 21, 2026

I couldn't understand why tests fail:

JavascriptException message:  Traceback (most recent call last):
  File "/lib/python313.zip/_pyodide/_base.py", line 597, in eval_code_async
    await CodeRunner(
    ...<9 lines>...
    .run_async(globals, locals)
  File "/lib/python313.zip/_pyodide/_base.py", line 411, in run_async
    coroutine = eval(self.code, globals, locals)
  File "<exec>", line 1, in <module>
  File "/lib/python3.13/site-packages/beartype/__init__.py", line 158, in <module>
    from beartype._decor.decormain import (
        beartype as beartype,
    )
  File "/lib/python3.13/site-packages/beartype/_decor/decormain.py", line 22, in <module>
    from beartype._conf.confcommon import BEARTYPE_CONF_DEFAULT
  File "/lib/python3.13/site-packages/beartype/_conf/confcommon.py", line 17, in <module>
    from beartype._conf.confmain import BeartypeConf
  File "/lib/python3.13/site-packages/beartype/_conf/confmain.py", line 49, in <module>
    from beartype._conf.conftest import (
    ...<4 lines>...
    )
ModuleNotFoundError: No module named 'beartype._conf.conftest'

What I've checked:
– The module exists in the source code: https://github.com/beartype/beartype/blob/v0.22.9/beartype/_conf/conftest.py
– The module exists in the wheel referenced by the link in the recipe
– The package, of this particular version, is supported by PyScript: https://packages.pyscript.net/?q=beartype
– I'm successfully using the package, of this particular version, with PyScript 2026.1.1 and Pyodide 0.29.1, for a few weeks already, and everything works fine.

I found no clue of why import may fail in the tests. :(

Could it be too many import nesting levels?
Could it be the word test in the module name?

Copy link
Copy Markdown
Member

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

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

Hi @jolaf, thank you for this PR! Yes, based on the repodata artifacts available at https://github.com/pyodide/pyodide-recipes/actions/runs/21222889001/artifacts/5209590752 (linked on the summary page at https://github.com/pyodide/pyodide-recipes/actions/runs/21222889001?pr=484), the conftest.py file was not included in the built wheel. For size reasons, we usually unvendor the tests from the wheel, as this helps reduce bandwidth usage when downloading packages in a browser.

There are two ways to fix this, and either can be chosen:

I would recommend the second one in this case.

So, while this is fixable for now, perhaps you could avoid it in a new version by restructuring the imports upstream to not rely on conftest.py, if possible?

@jolaf
Copy link
Copy Markdown
Author

jolaf commented Jan 22, 2026

For size reasons, we usually unvendor the tests from the wheel

Yes, I understand.

But this package does not contain tests. It is a runtime type checker, and the word "test" is extensively used in the code with the meaning of "check that the value type is as expected". And *test.py files contain collections or sets of such checks for various cases.

  • set unvendor-tests: false to stop this from happening
  • use this undocumented key to list the files that are needed for the package to be importable and should not be unvendored

The second options looks more appropriate, because the first one sounds like "let's allow this package to keep its tests", which is not the case.

I would recommend the second one in this case.

Ok, we agree on this.

So, while this is fixable for now, perhaps you could avoid it in a new version by restructuring the imports upstream to not rely on conftest.py, if possible?

I understand what you mean, but I don't think that would be appropriate. This file, as well as other 16 similarly named files in the package, are not something that can be "not relied on", they are part of its core functionality.

Also, I'm not a developer of the package, but just a user who's willing to make products one uses (PyScript/Pyodide, in this case) better.

@jolaf
Copy link
Copy Markdown
Author

jolaf commented Jan 23, 2026

Well, _retain_test_patterns is not working, unfortunately:

pydantic_core._pydantic_core.ValidationError: 1 validation error for MetaConfig
Value error, If source is a wheel, 'build/retain_test_patterns' key is not allowed [type=value_error, input_value={'package': {'name': 'bea...ype', 'license': 'MIT'}}, input_type=dict]

So I'm switching to unvendor-tests: false.

@github-actions
Copy link
Copy Markdown
Contributor

Package Build Results

Total packages built: 28
Total build time: 0:02:45

Package Build Times (click to expand)
Package Build Time
libopenssl 2m 41s
sqlite3 1m 27s
liblzma 1m 7s
test 25s
regex 12s
pydoc_data 4s
MarkupSafe 4s
pydecimal 4s
lzma 4s
ssl 4s
atomicwrites 3s
hashlib 3s
pytz 1s
py 1s
micropip 1s
attrs 1s
iniconfig 1s
Jinja2 1s
pytest-asyncio 1s
pluggy 1s
tblib 1s
pyparsing 1s
more-itertools 1s
pytest 1s
exceptiongroup 1s
setuptools 1s
beartype 1s
six 0s

Longest build: libopenssl (2m 41s)
Packages built in more than 10 minutes: 0

@agriyakhetarpal
Copy link
Copy Markdown
Member

agriyakhetarpal commented Jan 23, 2026

Well, _retain_test_patterns is not working, unfortunately:

pydantic_core._pydantic_core.ValidationError: 1 validation error for MetaConfig
Value error, If source is a wheel, 'build/retain_test_patterns' key is not allowed [type=value_error, input_value={'package': {'name': 'bea...ype', 'license': 'MIT'}}, input_type=dict]

So I'm switching to unvendor-tests: false.

Ah, thanks for checking and catching this! Considering that we unvendor the tests from the wheels anyway since unvendor-tests: is true by default, there should be no reason for us to disallow _retain_test_patterns. I will open a PR. In the meantime, this LGTM.

Copy link
Copy Markdown
Member

@ryanking13 ryanking13 left a comment

Choose a reason for hiding this comment

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

Same for this package (#485 (review)). beartype is a pure Python package that can be installed through micropip, so why do you want to add this package explicitly?

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.

3 participants