Attribute Error using `__setattr__` on Windows
See original GitHub issueWhen running the following code, it works fine on Python 3.6 on Ubuntu 18.02 but not Windows 10.
>>> import wrapt
>>> a = wrapt.ObjectProxy(None)
>>> a.__setattr__('__dict__', {})
It errors when trying to set the attribute:
elif hasattr(type(self), name):
> object.__setattr__(self, name, value)
E AttributeError: can't set attribute
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
AttributeError when using object.__setattr__ - Stack Overflow
I need an object having a single attribute (like foo) should I define a class (like FooClass) just for it? python · object...
Read more >SetAttr statement (VBA) | Microsoft Learn
A run-time error occurs if you try to set the attributes of an open file. Example. This example uses the SetAttr statement to...
Read more >[Solved] AttributeError: can't set attribute in python - Finxter
The easiest way to fix the AttributeError:can't set attribute is to create a new namedtuple object with the namedtuple._replace() method.
Read more >What is setattr in Python used for? - Toppr
When you try to call an attribute of an object whose type does not support that function, Python throws an AttributeError. In Python,...
Read more >"legend_label" unexpected attribute error (works in Windows ...
I am running into an issue with the “legend_label” attribute. Curiously enough, it works fine when I run it on my Windows system, ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

The original problem and difference you saw is that
__dict__can only be changed on a Python class implemented as Python code. TheObjectProxycan be pure Python code, or C code depending on whether compiler was present so that C code implementation could be installed. Trying to update it when it was implemented as C code will fail.Okay I think I have a clearer idea now what I need to do. (I am new to
wraptand this code was recently accepted into a project I own so trying to nail down how best for it to work. Sorry for any confusion!) The code was trying to set__dict__even when an object type that could be wrapped did not have that property.Thank you so much for the quick guidance!
Just as an aside, It’s actually possible to set
__dict__todictor anydictsubclass.