-
-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v0.9.0 errors for imports related to type declarations #245
Comments
Can reproduce with attrs. from __future__ import annotations
import typing
import attr
if typing.TYPE_CHECKING:
import datetime
...
@attr.s(eq=True, hash=False, init=True, kw_only=True, slots=True, weakref_slot=False)
class ActivityTimestamps:
"""The datetimes for the start and/or end of an activity session."""
start: typing.Optional[datetime.datetime] = attr.ib(repr=True)
"""When this activity's session was started, if applicable."""
end: typing.Optional[datetime.datetime] = attr.ib(repr=True)
"""When this activity's session will end, if applicable.""" Offending code appears to be in 0eb6777 that is raising this:
I would possibly argue that pdoc needs to be setting typing.TYPE_CHECKING to Another solution may be to parse the AST and work out what imports are available. in the scope you are observing annotations from. That way, you could link to other modules without having to physically import them as part of parsing the file. This would mean that side effects that the use of |
Currently failing to build from pdoc issue pdoc3/pdoc#245, so this will need to be updated when that issue gets resolved or reverted.
Currently failing to build from pdoc issue pdoc3/pdoc#245, so this will need to be updated when that issue gets resolved or reverted.
@kernc mind adding the |
Simply wrapping the lines: Lines 906 to 907 in 532d9a3
in if False would just bring back issue #210. Setting typing.TYPE_CHECKING is required in your cases. I think where it's set now should certainly cover the CLI-usage case.
If someone can confirm the master is fixed before a patch release pronto, that'd be awesome. 😁 |
What you did doesnt really fix it, since the whole point of
I think what @nekokatt suggested is the best approach for this. I think this might need a rewrite of how you get typehints |
Don't set `typing.TYPE_CHECKING` as it can result in circular imports. See #245 (comment) Instead, fallback to raw annotation strings when other, eval'ing methods fail. Ref: #245
Don't set `typing.TYPE_CHECKING` as it can result in circular imports. See #245 (comment) Instead, fallback to raw annotation strings when other, eval'ing methods fail. Ref: #245
Seems to work better now but I found a bug that I will probably open as another issue: import attrs
import typing
from hikari.utilities import attr_extensions
@typing.final
@attr_extensions.with_copy
@attr.s(frozen=True, kw_only=True)
class ConsolePalette:
"""Data class containing printable escape codes for colouring console output."""
default: str = attr.ib(default="")
bright: str = attr.ib(default="")
underline: str = attr.ib(default="")
invert: str = attr.ib(default="")
red: str = attr.ib(default="")
green: str = attr.ib(default="")
yellow: str = attr.ib(default="")
blue: str = attr.ib(default="")
magenta: str = attr.ib(default="")
cyan: str = attr.ib(default="")
white: str = attr.ib(default="")
bright_red: str = attr.ib(default="")
bright_green: str = attr.ib(default="")
bright_yellow: str = attr.ib(default="")
bright_blue: str = attr.ib(default="")
bright_magenta: str = attr.ib(default="")
bright_cyan: str = attr.ib(default="")
bright_white: str = attr.ib(default="")
framed: str = attr.ib(default="")
dim: str = attr.ib(default="") seems to cause
|
Any tracebacks? Better open a separate issue. 👍 Seems remotely related, but could also just be a decorator issue.
Good enough for a release, you think? 🙏 That, or the alternative to revert 0eb6777 which has caused it all. |
Looks good to me, also, found the issue that I pointed above looks to be with our lib, not pdoc 😅 |
Currently failing to build from pdoc issue pdoc3/pdoc#245, so this will need to be updated when that issue gets resolved or reverted. Added missing slot to BotAware. Froze isort to v5.4.2 Reformatted traits.
Expected Behavior
Should build the documentation normally
Actual Behavior
Doesn't build and errors with a
NameError
Steps to Reproduce
I have managed to isolate this into a small example. Consider this:
foo.py
bar.py
If you try to create the docs for these files, calling
pdoc3 --html foo bar
, you will getNameError: name 'BarClass' is not defined
.I tried adding
if typing.TYPE_CHECKING
conditional around this line:pdoc/pdoc/__init__.py
Lines 906 to 907 in 532d9a3
and it works. I'd be happy to send a PR with the fix.
Additional info
The text was updated successfully, but these errors were encountered: