Skip to content

Member is not assignable error when accessing a module member #5439

Closed

Description

@gilbsgilbs

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.

Activity

  1. ilevkivskyi commented on Aug 9, 2018

    @ilevkivskyi
    Member

    Thanks for reporting!

    This particular error is probably easy to fix, but then the best type we can give to foo.bar is types.ModuleType. Supporting things like foo.bar.reduce may be much harder.

  2. gilbsgilbs commented on Aug 9, 2018

    @gilbsgilbs
    Author

    Many thanks @ilevkivskyi for your insanely quick reply and tagging.

    This particular error is probably easy to fix, but then the best type we can give to foo.bar is types.ModuleType. Supporting things like foo.bar.reduce may be much harder.

    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
    • foo.bar will loose type safety?
    • foo.bar line 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 on r?

    Anyways, this would probably be preferable than raising an error since the use-case sounds 100% legitimate to me, wouldn't it?

  3. ilevkivskyi commented on Aug 9, 2018

    @ilevkivskyi
    Member

    do you mean that...

    No, I meant exactly your code in the original post.

  4. added a commit that references this issue on Aug 27, 2022
    3efbc5c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions