Skip to content

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

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

frommypy.nodesimportCallExpr, MemberExpr, NameExpr, get_member_expr_fullnamem1=MemberExpr(MemberExpr(NameExpr("a"), "b"), "c") # a.b.cm2=MemberExpr(CallExpr(NameExpr("a"), [], [], []), "b") # a().bm3=MemberExpr(MemberExpr(CallExpr(NameExpr("a"), [], [], []), "b"), "c") # a().b.c>>>get_member_expr_fullname(m1)
'a.b.c'>>>get_member_expr_fullname(m2) isNoneTrue>>>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