Repository navigation
Conversation
Author
|
Hi @mhils, could you take a look at this when you have a moment? Happy to fix up anything that needs changing. Thanks! |
Author
|
closing this one, no traction. thanks anyway |
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 #765.
For a
typing.NamedTuplewith a forward reference,pdoc emitted
Warn: Error parsing type annotation ForwardRef('Bar') for bug.Foo.__init__. Import of Bar failed: name 'Bar' is not defined, and the parameter type in the constructor signature stayed unresolved — even though the field itself resolved fine andtyping.get_type_hints(Foo)has no problem with this code.The cause: the
__new__that NamedTuple synthesizes is exec'd in a throwawaynamedtuple_Foomodule, soinspect.getmodule()returnsNonefor it.Function.signaturethen evaluated the annotations against an empty global namespace (andsafe_eval_type's TYPE_CHECKING fallback is skipped entirely when the module isNone). Dataclasses don't hit this because their generated__init__runs in the defining module's globals.Fix: in
Function.signature, ifinspect.getmodule()finds no module, fall back to the module being documented (sys.modules[self.modulename]), which is the namespace the class was defined in.Tests: new
test_namedtuple_forward_ref_init_signatureintest/test_doc.pybuilds the example above in a synthetic module and asserts that the__init__signature resolvesbtoBarwithout warnings (and that the field variable resolves as well). It fails on the unmodified code. Full test suite: the failure set is identical to master in my environment (a number of html snapshot comparisons and the mtime tests fail there too, unrelated to this change).