[issue22123] Make object() behave exactly like types.SimpleNamespace() if given kwargs

2014-08-02 Thread Terry J. Reedy

Terry J. Reedy added the comment:

Making types.SimpleNamespace more easily available might be a good idea. 
Screwing around with our fundamental base class to do so is not.  Neither is 
rebinding the builtin name 'object'.  Find a different way to accomplish the 
goal.

SimpleNamespace *could* have been added to builtins, but was not.  Instead, it 
was added to types, which is the catchall for types not used enough to be in 
builtins.  Someone might check the issue or list discussion as to why.

At one time object had the bug of silently ignoring arguments. Years ago, Guido 
insisted that this be fixed and wrote patches himself. See #1683368. For one 
thing, raising the exception catches bugs with cooperative multiple inheritance 
and super calls. I believe having object() return a subclass of object that in 
not a superclass of other classes would be worse than the previous bug.

I think this idea should have been left on python-list or moved to python-ideas 
for further development.  I am sure that the proposal as stated should be 
rejected.

--
nosy: +terry.reedy
stage:  -> test needed

___
Python tracker 

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



[issue22123] Make object() behave exactly like types.SimpleNamespace() if given kwargs

2014-08-02 Thread Mark Lawrence

Mark Lawrence added the comment:

As a work around for the originator how about

>>> pyobject = object # keep reference to built-in.
>>> from types import SimpleNamespace as object
>>> help(object)
Help on class SimpleNamespace in module types:
...

???

--
nosy: +BreamoreBoy

___
Python tracker 

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



[issue22123] Make object() behave exactly like types.SimpleNamespace() if given kwargs

2014-08-02 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

This will be fragile because the behavior will be depend from the number of 
keyword argument. Hypothetic example:

>>> kwargs = {'a': 1}
>>> obj = object(**kwargs)
>>> obj.b = 2  # success
>>> kwargs = {}  # empty
>>> obj = object(**kwargs)
>>> obj.b = 2
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'object' object has no attribute 'b'

For now you need only one or two line of code to declare new class.

>>> class Object: pass
... 
>>> obj = Object()
>>> obj.a = 1
>>> obj.b = 2

--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue22123] Make object() behave exactly like types.SimpleNamespace() if given kwargs

2014-08-02 Thread Ethan Furman

Changes by Ethan Furman :


--
nosy: +ethan.furman

___
Python tracker 

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



[issue22123] Make object() behave exactly like types.SimpleNamespace() if given kwargs

2014-08-02 Thread Barry A. Warsaw

Changes by Barry A. Warsaw :


--
nosy: +barry

___
Python tracker 

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



[issue22123] Make object() behave exactly like types.SimpleNamespace() if given kwargs

2014-08-02 Thread Mark Summerfield

New submission from Mark Summerfield:

Right now object() does not accept any args and returns the lightest possible 
featureless object (i.e., without even a __dict__).

This is great.

However, it is really useful sometimes to be able to create an object to hold 
some editable state (so not a namedtuple). Right now this can be done with 
types.SimpleNamespace().

I think it would be a useful enhancement to have object() work as it does now, 
but to allow it to accept kwargs in which case it would provide identical 
functionality to types.SimpleNamespace().

This arises from an email I wrote to the python mailinglist:
https://groups.google.com/d/msg/comp.lang.python/9pY7hLp8lDg/voYF8nMO6x8J

But I also think it would be useful more generally.

--
components: Interpreter Core
messages: 224539
nosy: mark
priority: normal
severity: normal
status: open
title: Make object() behave exactly like types.SimpleNamespace() if given kwargs
type: enhancement
versions: Python 3.5

___
Python tracker 

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