Member is not assignable error when accessing a module member #5439
Copy link
Copy link
Closed
Labels
bugmypy got something wrongmypy got something wrongfalse-positivemypy gave an error on correct codemypy gave an error on correct codeneeds discussionpriority-1-normal
Description
Hi,
This issue seems close to the one that was fixed in this PR.
- Are you reporting a bug, or opening a feature request?
I'm reporting a bug.
- Please insert below the code you are checking with mypy,
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
import functools
class Foo:
bar = functools
foo = Foo()
foo.bar # error: Member "bar" is not assignable- What is the actual behavior/output?
test.py:7: error: Member "bar" is not assignable
- What is the behavior/output you expect?
No Error. I'm just accessing, not mutating.
- What are the versions of mypy and Python you are using?
Do you see the same issue after installing mypy from Git master?
$ mypy --version
mypy 0.620
Same error on master.
- What are the mypy flags you are using? (For example --strict-optional)
No flags. Just raw mypy test.py
If you need any further information, please let me know.
Thank you in advance.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongfalse-positivemypy gave an error on correct codemypy gave an error on correct codeneeds discussionpriority-1-normal
Activity
ilevkivskyi commentedon Aug 9, 2018
Thanks for reporting!
This particular error is probably easy to fix, but then the best type we can give to
foo.baristypes.ModuleType. Supporting things likefoo.bar.reducemay be much harder.gilbsgilbs commentedon Aug 9, 2018
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:
foo.barwill loose type safety?foo.barline will raise an error, just as reproduced in this issue?Also, does this mean that, if in my first post example I write
r = foo.bar.reduce, I will loose type safety onr?Anyways, this would probably be preferable than raising an error since the use-case sounds 100% legitimate to me, wouldn't it?
ilevkivskyi commentedon Aug 9, 2018
No, I meant exactly your code in the original post.
Allow using modules as subtypes of protocols (#13513)