Repository navigation
Fix TypeError serving a namespace package in http_server mode - #479
Open
cristianchiriac wants to merge 1 commit into
Open
cristianchiriac wants to merge 1 commit into
cristianchiriac wants to merge 1 commit into
Conversation
Namespace packages (no __init__.py) have __file__ set to None. The html.mako auto-reload script and _WebDoc.check_modified() both called os.stat() on that None value directly, crashing with "TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType" instead of rendering the page. Skip the auto-reload script in the template when there's no real file to stat, and treat a namespace package as always-modified in check_modified() instead of raising. Fixes pdoc3#461
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #461.
Bug
A namespace package's
__file__attribute isNone(not missing — Python sets it explicitly toNonefor PEP 420 namespace packages):Two places in pdoc's dev server pass that
Nonestraight toos.stat():html.mako's auto-reload script:${os.stat(module.obj.__file__).st_mtime}, evaluated while rendering the page itself._WebDoc.check_modified()incli.py:os.stat(module.__file__).st_mtime, used by the auto-reload polling'sHEADrequests.Navigating to a namespace-package module's page crashes while rendering (matching the traceback in the issue), and even if that were avoided, the
HEADpolling from the auto-reload script would crash the same way.Fix
html.mako: only emit the auto-reload script whenmodule.obj.__file__is set, since there's nothing meaningful to stat for a namespace package.cli.py:check_modified()now checks formodule.__file__ is Noneup front and treats it as "modified" (HTTP 205) rather than crashing.Test plan
test_namespace_html_http_serverinpdoc/test/__init__.py, reusing the existing_namespaceexample-package fixtures, which renders a namespace package's HTML withhttp_server=True.TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneTypefrom the issue, and passes with the fix.python -m unittest pdoc.test: 84 tests, same 5 pre-existing failures with or without this change (Windows CRLF vs.\nline-ending mismatches intest_text/test_text_identifier/etc., unrelated to this fix — confirmed identical failure list on unmodifiedmaster).flake8on the changed Python files: clean.