-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Member is not assignable error when accessing a module member #5439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for reporting! This particular error is probably easy to fix, but then the best type we can give to |
Many thanks @ilevkivskyi for your insanely quick reply and tagging.
You know the implications way better than me, but just to be sure I understand, do you mean that: import functools
class Foo:
bar = functools.reduce
foo = Foo()
foo.bar
Also, does this mean that, if in my first post example I write Anyways, this would probably be preferable than raising an error since the use-case sounds 100% legitimate to me, wouldn't it? |
No, I meant exactly your code in the original post. |
Fixes #5018 Fixes #5439 Fixes #10850 The implementation is simple but not the most beautiful one. I simply add a new slot to the `Instance` class that represents content of the module. This new attribute is short lived (it is not serialized, and not even stored on variables etc., because we erase it in `copy_modified()`). We don't need to store it, because all the information we need is already available in `MypyFile` node. We just need the new attribute to communicate between the checker and `subtypes.py`. Other possible alternatives like introducing new dedicated `ModuleType`, or passing the symbol tables to `subtypes.py` both look way to complicated. Another argument in favor of this new slot is it could be useful for other things, like `hasattr()` support and ad hoc callable attributes (btw I am already working on the former). Note there is one important limitation: since we don't store the module information, we can't support module objects stored in nested positions, like `self.mods = (foo, bar)` and then `accepts_protocol(self.mods[0])`. We only support variables (name expressions) and direct instance, class, or module attributes (see tests). I think this will cover 99% of possible use-cases.
Hi,
This issue seems close to the one that was fixed in this PR.
I'm reporting a bug.
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
No Error. I'm just accessing, not mutating.
Do you see the same issue after installing mypy from Git master?
Same error on master.
No flags. Just raw
mypy test.py
If you need any further information, please let me know.
Thank you in advance.
The text was updated successfully, but these errors were encountered: