<br><br><div class="gmail_quote">On Mon, Jul 20, 2009 at 05:22, Nick Coghlan <span dir="ltr"><<a href="mailto:ncoghlan@gmail.com">ncoghlan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">brett.cannon wrote:<br>
> Author: brett.cannon<br>
> Date: Mon Jul 20 06:23:48 2009<br>
> New Revision: 74110<br>
><br>
> Log:<br>
> Implement the PEP 302 protocol for get_filename() as<br>
> importlib.abc.ExecutionLoader. PyLoader now inherits from this ABC instead of<br>
> InspectLoader directly. Both PyLoader and PyPycLoader provide concrete<br>
> implementations of get_filename in terms of source_path and bytecode_path.<br>
><br>
><br>
> Modified:<br>
> python/branches/py3k/Doc/library/importlib.rst<br>
> python/branches/py3k/Lib/importlib/_bootstrap.py<br>
> python/branches/py3k/Lib/importlib/abc.py<br>
> python/branches/py3k/Lib/importlib/test/source/test_abc_loader.py<br>
> python/branches/py3k/Lib/importlib/test/test_abc.py<br>
> python/branches/py3k/Misc/NEWS<br>
><br>
> Modified: python/branches/py3k/Doc/library/importlib.rst<br>
> ==============================================================================<br>
> --- python/branches/py3k/Doc/library/importlib.rst (original)<br>
> +++ python/branches/py3k/Doc/library/importlib.rst Mon Jul 20 06:23:48 2009<br>
> @@ -202,10 +202,24 @@<br>
> :term:`loader` cannot find the module.<br>
><br>
><br>
> +.. class:: ExecutionLoader<br>
> +<br>
> + An abstract base class which inherits from :class:`InspectLoader` that,<br>
> + when implemented, allows a module to be executed as a script. The ABC<br>
> + represents an optional :pep:`302` protocol.<br>
> +<br>
> + .. method:: get_filename(fullname)<br>
> +<br>
> + An abstract method that is to return the value for :attr:`__file__` for<br>
> + the specified module. If no path is available, :exc:`ImportError` is<br>
> + raised.<br>
<br>
</div></div>This isn't quite accurate:<br>
<br>
1. Modules that come from a loader without get_filename() can still be<br>
executed via the runpy module. They will just have __file__ set to None<br>
instead of the value that would have been set by load_module() (and if<br>
they were executed with -m then sys.argv[0] will be wrong as well).<br>
</blockquote><div><br></div><div>Changed it to say it helps.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
2. There's an additional restriction on get_filename(): it isn't allowed<br>
to load the module (otherwise there is no point to the method - if<br>
loading the module was acceptable, then runpy could just do that and<br>
inspect __file__ itself as a fallback when the loader didn't provide<br>
get_filename()).</blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
I have a feeling that I didn't mention point 2 explicitly when I<br>
documented get_filename() in PEP 302 though.<br>
</blockquote><div><br></div><div>Nope, it isn't in the docs, but I believe it is implied for all the protocols from PEP 302 short of load_module.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
Regards,<br>
Nick.<br>
<font color="#888888"><br>
--<br>
Nick Coghlan | <a href="mailto:ncoghlan@gmail.com">ncoghlan@gmail.com</a> | Brisbane, Australia<br>
---------------------------------------------------------------<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
Python-checkins mailing list<br>
<a href="mailto:Python-checkins@python.org">Python-checkins@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-checkins" target="_blank">http://mail.python.org/mailman/listinfo/python-checkins</a><br>
</div></div></blockquote></div><br>