-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
bug: functions defined in markdown-exec
context don't have a __module__
#47
Comments
Hi @femtomc, thanks for the report 🙂 I ran some experiment and it's indeed possible to fix this, by adding a Would beartype be OK with |
I'm not entirely sure! I don't know if it does any further introspection on the module -- perhaps the maintainer will comment on my issue there and we'll know better |
OK thanks 🙂 I think I'll go with a |
Thank you so much! |
Ah, it's causing other issues unfortunately 🤔 I'm getting this traceback on my own executed code blocks now: Traceback (most recent call last):
File "/media/data/dev/markdown-exec/src/markdown_exec/formatters/python.py", line 61, in _run_python
exec(compiled, exec_globals) # noqa: S102
File "<code block: session insiders; n2>", line 31, in <module>
class Project:
File "/home/pawamoy/.basher-packages/pyenv/pyenv/versions/3.8.18/lib/python3.8/dataclasses.py", line 1019, in dataclass
return wrap(cls)
File "/home/pawamoy/.basher-packages/pyenv/pyenv/versions/3.8.18/lib/python3.8/dataclasses.py", line 1011, in wrap
return _process_class(cls, init, repr, eq, order, unsafe_hash, frozen)
File "/home/pawamoy/.basher-packages/pyenv/pyenv/versions/3.8.18/lib/python3.8/dataclasses.py", line 861, in _process_class
cls_fields = [_get_field(cls, name, type)
File "/home/pawamoy/.basher-packages/pyenv/pyenv/versions/3.8.18/lib/python3.8/dataclasses.py", line 861, in <listcomp>
cls_fields = [_get_field(cls, name, type)
File "/home/pawamoy/.basher-packages/pyenv/pyenv/versions/3.8.18/lib/python3.8/dataclasses.py", line 712, in _get_field
and _is_type(f.type, cls, typing, typing.ClassVar,
File "/home/pawamoy/.basher-packages/pyenv/pyenv/versions/3.8.18/lib/python3.8/dataclasses.py", line 658, in _is_type
ns = sys.modules.get(cls.__module__).__dict__
AttributeError: 'NoneType' object has no attribute '__dict__' |
@pawamoy Not a big deal if can't fix on this side, I can do a bit of hacking (and see what the |
Seems I can fix it with this: module_name = re.sub(r"[^a-zA-Z\d]+", "_", code_block_id)
exec_globals["__name__"] = module_name
sys.modules[module_name] = ModuleType(module_name) I worry about other potential side-effects 🤔 |
I'll push it, and if it breaks I'll revert. |
haha, that's the spirit! Again, no worries if you have to revert. |
Let me know if v1.8.2 works better for you 🙂 |
Re -- @pawamoy, if you have some time, can you examine the response by Cecil over at beartype/beartype#381 (comment) (the responses from Cecil on the repo are in a great style) There's one section in particular which I'm wondering about: When the Badness Get Going, the Code Get Blowing Up Are the things that Cecil is saying in this section true of
I believe this might also explain some weird omissions in my |
As answered in the linked issue, it's possible that my own import of future annotations is leaking into the context of the executed code block. Were you able to try v1.8.2 though? I'm not sure to understand if you have a new error or if this works now. |
The original problem is fixed on v1.8.2 now! The issue I alluded to is a new one! I can file a new one. |
Thanks, yeah that'd be great 🙂 |
Hey @femtomc, no need for a new issue, I've just released v1.8.3 which should fix it 🙂 Let me know if that works for you. |
When I define functions inside a
markdown-exec
block, the functions don't possess the__module__
attribute:returns
None
This, unfortunately, interacts poorly with systems that expect a
__module__
attribute (beartype/beartype#381)For instance, I was attempting to setup some documentation to show my users what a
beartype
error would look like, but ran into this issue wherebeartype
expects the callable which it is typechecking to have a__module__
attribute (beartype/beartype#381).Is it possible to configure
markdown-exec
to supply a dummy module? Or to use thesession
string as the dummy module?Environment
Working with:
markdown-exec==1.8.1
The text was updated successfully, but these errors were encountered: