[issue35119] Customizing module attribute access example raises RecursionError

2018-11-05 Thread Ivan Levkivskyi


Change by Ivan Levkivskyi :


--
nosy:  -miss-islington
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



[issue35119] Customizing module attribute access example raises RecursionError

2018-11-05 Thread miss-islington


miss-islington  added the comment:


New changeset 558dc8adbec0b85e0ff257fcedc85c5d89cd2825 by Miss Islington (bot) 
in branch '3.7':
bpo-35119: Fix RecursionError in example of customizing module attribute 
access. (GH-10323)
https://github.com/python/cpython/commit/558dc8adbec0b85e0ff257fcedc85c5d89cd2825


--
nosy: +miss-islington

___
Python tracker 

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



[issue35119] Customizing module attribute access example raises RecursionError

2018-11-05 Thread miss-islington


Change by miss-islington :


--
pull_requests: +9648

___
Python tracker 

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



[issue35119] Customizing module attribute access example raises RecursionError

2018-11-05 Thread Ivan Levkivskyi


Ivan Levkivskyi  added the comment:


New changeset 0bee3c36d406e47fa9f99cfc1e07b701512c4f3f by Ivan Levkivskyi 
(Denis Osipov) in branch 'master':
bpo-35119: Fix RecursionError in example of customizing module attribute 
access. (GH-10323)
https://github.com/python/cpython/commit/0bee3c36d406e47fa9f99cfc1e07b701512c4f3f


--

___
Python tracker 

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



[issue35119] Customizing module attribute access example raises RecursionError

2018-11-04 Thread Denis Osipov


Change by Denis Osipov :


--
keywords: +patch
pull_requests: +9625
stage: needs patch -> patch review

___
Python tracker 

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



[issue35119] Customizing module attribute access example raises RecursionError

2018-11-04 Thread Ivan Levkivskyi


Ivan Levkivskyi  added the comment:

Ah, sorry, I didn't understand this was a documentation issue. Please feel free 
to submit a PR that fixes the example to use `super().__setattr__()`.

--
resolution: not a bug -> 
stage: resolved -> needs patch
status: closed -> open

___
Python tracker 

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



[issue35119] Customizing module attribute access example raises RecursionError

2018-11-04 Thread Denis Osipov


Denis Osipov  added the comment:

I understand that it's expected behavior. But why don't use completely working 
example in the docs, which one could just copy and paste? It requires to add 
just seven chars)

--

___
Python tracker 

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



[issue35119] Customizing module attribute access example raises RecursionError

2018-10-31 Thread Ivan Levkivskyi


Ivan Levkivskyi  added the comment:

Yes, this is expected, you should use ``super().__setattr__()``.

--
resolution:  -> not a bug
stage:  -> 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



[issue35119] Customizing module attribute access example raises RecursionError

2018-10-31 Thread Ronald Oussoren


Ronald Oussoren  added the comment:

I'm not convinced that any change is needed, this is completely expected 
behaviour (and not special to modules).

The following code also raises RecursionError:

class VerboseObject:
def __setattr__(self, nm, value):
print(f"Setting {nm} to {value}")
setattr(self, nm, value)

o = VerboseObject()
o.a = 42

This is because setattr() calls the __setattr__ method, which calls setattr() 
again, ... .


The fix is to call super().__setattr__ instead:

class VerboseObject:
def __setattr__(self, nm, value):
print(f"Setting {nm} to {value}")
super().__setattr__(nm, value)

o = VerboseObject()
o.a = 42

--
nosy: +ronaldoussoren

___
Python tracker 

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



[issue35119] Customizing module attribute access example raises RecursionError

2018-10-31 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

Thanks for the report Denis. Would you like to propose a PR for this? The file 
is at https://github.com/python/cpython/blob/master/Doc/reference/datamodel.rst 
. This was added as part of 5364b5cd757. I am adding Ivan who added the example 
for confirmation and review.

--
nosy: +levkivskyi, xtreak

___
Python tracker 

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



[issue35119] Customizing module attribute access example raises RecursionError

2018-10-30 Thread Denis Osipov


New submission from Denis Osipov :

Customizing module attribute access example raises RecursionError:

>>> import sys
>>> from types import ModuleType
>>> class VerboseModule(ModuleType):
... def __repr__(self):
... return f'Verbose {self.__name__}'
... def __setattr__(self, attr, value):
... print(f'Setting {attr}...')
... setattr(self, attr, value)
...
>>> sys.modules[__name__].__class__ = VerboseModule
>>> sys.modules[__name__].a = 5
Setting a...
<...>
Setting a...
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 6, in __setattr__
  File "", line 6, in __setattr__
  File "", line 6, in __setattr__
  [Previous line repeated 495 more times]
  File "", line 5, in __setattr__
RecursionError: maximum recursion depth exceeded while calling a Python object
Setting a...>>>

Something like this can fix it:

def __setattr__(self, attr, value):
... print(f'Setting {attr}...')
... super().setattr(self, attr, value)

--
assignee: docs@python
components: Documentation
messages: 328966
nosy: denis-osipov, docs@python
priority: normal
severity: normal
status: open
title: Customizing module attribute access example raises RecursionError
type: behavior
versions: Python 3.7, Python 3.8

___
Python tracker 

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