[issue37623] namedtuple integration for importlib.abc.Loader

2019-07-18 Thread Andrew Yurisich


New submission from Andrew Yurisich :

I wanted to return a namedtuple from a concrete implementation of an 
importlib.abc.Loader base class, and wasn't able to provide a __spec__ property 
on the underlying class behind the namedtuple. All return values from 
importlib.abc.Loader#create_module need to have a __spec__ property set.

Similar to the namedtuple optional argument 'module', I'd like to be able to 
pass in a 'spec', and add this value to result.__spec__ before returning the 
final result.

--
components: Library (Lib)
messages: 348124
nosy: Andrew Yurisich
priority: normal
severity: normal
status: open
title: namedtuple integration for importlib.abc.Loader
type: enhancement
versions: Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9

___
Python tracker 
<https://bugs.python.org/issue37623>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37623] namedtuple integration for importlib.abc.Loader

2019-07-19 Thread Andrew Yurisich

Andrew Yurisich  added the comment:

You're right, I was invoking the namedtuple on the same line that I was
defining it, freezing it in the process.

I split it to into two statements, and snuck the __spec__ attribute between
the definition and the instantiation.

I'll update the examples on my GitHub issue in the morning, and probably
close the issue out unless I find something else that is blocking me.

Thanks for the input 👍

On Fri, Jul 19, 2019, 22:08 Serhiy Storchaka  wrote:

>
> Serhiy Storchaka  added the comment:
>
> It is not hard to set __spec__ (as well as any other attributes) after
> creating a namedtuple class.
>
> A = namedtuple(...)
> A.__spec__ = ...
>
> or
>
> class A(namedtuple(...)):
> __spec__ = ...
>
> __spec__ do not have anything to namedtuple. It is not like __module__ or
> __doc__ setting which would benefit almost every public namedtuple class.
> It is not even special for types.
>
> --
> nosy: +serhiy.storchaka
>
> ___
> Python tracker 
> <https://bugs.python.org/issue37623>
> ___
>

--

___
Python tracker 
<https://bugs.python.org/issue37623>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37623] namedtuple integration for importlib.abc.Loader

2019-07-19 Thread Andrew Yurisich


Andrew Yurisich  added the comment:

This issue was raised due to a misunderstanding of the namedtuple creation 
process. After creating the fields, but before assigning them, __spec__ is 
trivially added to namedtuple class' definition as a property.

Thanks again @serhiy.storchaka

--
resolution:  -> works for me
stage: patch review -> resolved
status: open -> closed

___
Python tracker 
<https://bugs.python.org/issue37623>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37623] namedtuple integration for importlib.abc.Loader

2019-08-04 Thread Andrew Yurisich


Andrew Yurisich  added the comment:

If anyone is interested in the progress I was able to make as a result of this 
discussion, feel free to check out 
https://github.com/captain-kark/python-module-resources/blob/d85453ff4f5022127874a5842449d95bb5eda234/module_resources/module_resources.py
 and leave you feedback or comments.

--

___
Python tracker 
<https://bugs.python.org/issue37623>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com