[issue39336] Immutable module type can't be used as package in custom loader

2020-01-27 Thread STINNER Victor


STINNER Victor  added the comment:

commit 2528a6c3d0660c03ae43d796628462ccf8e58190
Author: Dino Viehland 
Date:   Mon Jan 27 14:04:56 2020 -0800

Add test.test_import.data.unwritable package to makefile (#18211)

--

___
Python tracker 

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



[issue39336] Immutable module type can't be used as package in custom loader

2020-01-27 Thread STINNER Victor


STINNER Victor  added the comment:

test_unwritable_module() fails on AMD64 Fedora Stable Clang Installed 3.x: 
bpo-39459.

--
nosy: +vstinner

___
Python tracker 

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



[issue39336] Immutable module type can't be used as package in custom loader

2020-01-22 Thread Dino Viehland


Change by Dino Viehland :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

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



[issue39336] Immutable module type can't be used as package in custom loader

2020-01-22 Thread Dino Viehland


Dino Viehland  added the comment:


New changeset 9b6fec46513006d7b06fcb645cca6e4f5bf7c7b8 by Dino Viehland in 
branch 'master':
bpo-39336: Allow packages to not let their child modules be set on them (#18006)
https://github.com/python/cpython/commit/9b6fec46513006d7b06fcb645cca6e4f5bf7c7b8


--

___
Python tracker 

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



[issue39336] Immutable module type can't be used as package in custom loader

2020-01-17 Thread Dong-hee Na


Dong-hee Na  added the comment:

I apologize for the noise caused by the wrong PR connection.

--
nosy: +corona10

___
Python tracker 

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



[issue39336] Immutable module type can't be used as package in custom loader

2020-01-17 Thread Dong-hee Na


Change by Dong-hee Na :


--
pull_requests:  -17433

___
Python tracker 

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



[issue39336] Immutable module type can't be used as package in custom loader

2020-01-17 Thread Dong-hee Na


Change by Dong-hee Na :


--
pull_requests:  -17431

___
Python tracker 

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



[issue39336] Immutable module type can't be used as package in custom loader

2020-01-17 Thread Dong-hee Na


Change by Dong-hee Na :


--
pull_requests: +17433
pull_request: https://github.com/python/cpython/pull/18035

___
Python tracker 

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



[issue39336] Immutable module type can't be used as package in custom loader

2020-01-17 Thread Dong-hee Na


Change by Dong-hee Na :


--
pull_requests: +17431
pull_request: https://github.com/python/cpython/pull/18035

___
Python tracker 

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



[issue39336] Immutable module type can't be used as package in custom loader

2020-01-14 Thread Dino Viehland


Dino Viehland  added the comment:

I think the warning shouldn't be too bad.  It looks like ImportWarnings are 
filtered by default already, and the extra overhead of raising a warning in 
this case probably is nothing compared to the actual work in loading the module.

--

___
Python tracker 

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



[issue39336] Immutable module type can't be used as package in custom loader

2020-01-14 Thread Dino Viehland


Change by Dino Viehland :


--
keywords: +patch
pull_requests: +17406
stage: needs patch -> patch review
pull_request: https://github.com/python/cpython/pull/18006

___
Python tracker 

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



[issue39336] Immutable module type can't be used as package in custom loader

2020-01-14 Thread Brett Cannon


Brett Cannon  added the comment:

So I think this is way too marginal a use-case to expand the API to let loaders 
inject themselves into the semantics of it.

I assume going with option 1 but raising an ImportWarning would be too noisy 
for your use-case? If not I'm totally fine with that solution.

--

___
Python tracker 

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



[issue39336] Immutable module type can't be used as package in custom loader

2020-01-14 Thread Dino Viehland


Change by Dino Viehland :


--
nosy: +brett.cannon

___
Python tracker 

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



[issue39336] Immutable module type can't be used as package in custom loader

2020-01-14 Thread Dino Viehland


New submission from Dino Viehland :

I'm trying to create a custom module type for a custom loader where the 
returned modules are immutable.  But I'm running into an issue where the 
immutable module type can't be used as a module for a package.  That's because 
the import machinery calls setattr to set the module as an attribute on it's 
parent in _boostrap.py

# Set the module as an attribute on its parent.
parent_module = sys.modules[parent]
setattr(parent_module, name.rpartition('.')[2], module)

I'd be okay if for these immutable module types they simply didn't have their 
children packages published on them.

A simple simulation of this is a package which replaces its self with an object 
which doesn't support adding arbitrary attributes:

x/__init__.py:
import sys

class MyMod(object):
__slots__ = ['__builtins__', '__cached__', '__doc__', '__file__', 
'__loader__', '__name__', '__package__', '__path__', '__spec__']
def __init__(self):
for attr in self.__slots__:
setattr(self, attr, globals()[attr])


sys.modules['x'] = MyMod()

x/y.py:
# Empty file

>>> from x import y
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 983, in _find_and_load
  File "", line 971, in _find_and_load_unlocked
AttributeError: 'MyMod' object has no attribute 'y'

There's a few different options I could see on how this could be supported:
1) Simply handle the attribute error and allow things to continue
2) Add ability for the modules loader to perform the set, and fallback to 
setattr if one isn't available.  Such as:
 getattr(parent_module, 'add_child_module', setattr)(parent_module, 
name.rpartition('.')[2], module)
3) Add the ability for the module type to handle the setattr:
 getattr(type(parent_module), 'add_child_module', 
fallback)(parent_module, 
, name.rpartition('.')[2], module)

--
assignee: dino.viehland
components: Interpreter Core
messages: 36
nosy: dino.viehland
priority: normal
severity: normal
stage: needs patch
status: open
title: Immutable module type can't be used as package in custom loader
type: behavior

___
Python tracker 

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