Skip to content

Conversation

@iFreilicht
Copy link
Contributor

@iFreilicht iFreilicht commented Jan 28, 2025

Trying to use pdoc -o instead of pdoc in my project caused a long stacktrace with this error at the end:

File "/Users/feuh/.../.venv/lib/python3.12/site-packages/pdoc/doc.py", line 640, in _var_annotations
    _safe_getattr(cls, "__module__", "") + "." + cls.__qualname__
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

This was caused by one class' __module__ attribute being None.

I could not find the reason why that happens and why it happens only when using -o, but this change ensures it won't be a problem again.

Copy link
Member

@mhils mhils left a comment

Choose a reason for hiding this comment

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

I don't think changing the behavior of _safe_getattr is sensible as that is supposed to mirror getattr. Can we do an or "" at the callsite please?

@iFreilicht iFreilicht force-pushed the fix-typeerror-when-module-is-none branch from 8b029a5 to 627fbc4 Compare January 30, 2025 08:55
@iFreilicht
Copy link
Contributor Author

Yeah I see what you mean. I was debating between the two solutions myself. Fixed!

Copy link
Member

@mhils mhils left a comment

Choose a reason for hiding this comment

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

Thanks!

@mhils mhils enabled auto-merge (squash) January 30, 2025 09:08
iFreilicht and others added 2 commits February 19, 2025 11:50
Trying to use `pdoc -o` instead of `pdoc` in my project caused a long
stacktrace with this error at the end:

    File "/Users/feuh/.../.venv/lib/python3.12/site-packages/pdoc/doc.py", line 640, in _var_annotations
        _safe_getattr(cls, "__module__", "") + "." + cls.__qualname__
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
    TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

This was caused by one class' `__module__` attribute being `None`.

I could not find the reason why that happens and why it happens only
when using `-o`, but this change ensures it won't happen again.
@mhils mhils force-pushed the fix-typeerror-when-module-is-none branch from 2b3cb0a to b4b1dbe Compare February 19, 2025 10:51
@mhils mhils merged commit 4a5fd51 into mitmproxy:main Feb 19, 2025
14 checks passed
@iFreilicht iFreilicht deleted the fix-typeerror-when-module-is-none branch March 11, 2025 21:33
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.

2 participants