-
Notifications
You must be signed in to change notification settings - Fork 27
feat & refactor: Support forward references in ProtoStruct
#19
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
Conversation
先别合( |
228f864
to
e1e24ff
Compare
应该没问题了.jpg |
?forwardref直接用它自己的_evaluate就行了啊 |
@RF-Tar-Railt 能再帮着看下嘛,感谢 |
我不确定靠导入模块拿globals的行为是否可靠,相比通过frame查找。。。 这块或许还得看看pydanticV1是怎么做的 |
这样写的话应该单文件内的前向引用都没有问题吧🤔 |
def _resolve_annotations(arg: Union[Type["ProtoStruct"], "ProtoStruct"]) -> None: | ||
if not arg._delay_anno_map: | ||
return | ||
local = importlib.import_module(arg.__module__).__dict__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这一块可以加一段先从 sys.modules 找模块:
if globalns is None:
base_globals = sys.modules[base.__module__].__dict__
else:
base_globals = globalns
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
另外我感觉整个annotations的实现都得改一下,多利用typing里现有的东西(例如 get_type_hints 之类的)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
纯typing不太好弄的样子,暴露的接口太少
ProtoStruct
ProtoStruct
fix on #36 |
Now you can using forward references in ProtoStruct class, like below: