Skip to content
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

mypy.nodes.get_member_expr_fullname can return strings with embeded "None" #17847

Closed
brianschubert opened this issue Sep 28, 2024 · 0 comments · Fixed by #17848
Closed

mypy.nodes.get_member_expr_fullname can return strings with embeded "None" #17847

brianschubert opened this issue Sep 28, 2024 · 0 comments · Fixed by #17848
Labels
bug mypy got something wrong

Comments

@brianschubert
Copy link
Collaborator

brianschubert commented Sep 28, 2024

Bug Report

mypy.nodes.get_member_expr_fullname formats a MemberExpr into a dotted-name string if possible, or returns None if formatting the MemberExpr in that way is not possible (i.e. it contains expressions other than names and attribute accesses).

Sometimes when a dotted-name representation is not possible, it will return a string with an embedded "None" (e.g. "None.a.b.c") instead of returning None.

Encountered when reviewing #17178

To Reproduce

from mypy.nodes import CallExpr, MemberExpr, NameExpr, get_member_expr_fullname

m1 = MemberExpr(MemberExpr(NameExpr("a"), "b"), "c")                        # a.b.c
m2 = MemberExpr(CallExpr(NameExpr("a"), [], [], []), "b")                   # a().b
m3 = MemberExpr(MemberExpr(CallExpr(NameExpr("a"), [], [], []), "b"), "c")  # a().b.c

>>> get_member_expr_fullname(m1)
'a.b.c'
>>> get_member_expr_fullname(m2) is None
True
>>> get_member_expr_fullname(m3)
'None.c'  # uh oh! expected None

Your Environment

  • Mypy version used: master (1.12.0+dev.26a77f9d37)
  • Mypy command-line flags: N/A
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.12.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant