Skip to content

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

Closed
@brianschubert

Description

@brianschubert

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions