Skip to content

gh-107883: Argument Clinic: Handle full module/class path in Function.fulldisplayname #107884

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

Merged
merged 7 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,60 @@ def test_parameters_required_after_star(self):
with self.subTest(block=block):
self.expect_failure(block, err)

def test_fulldisplayname_class(self):
dataset = (
("T", """
class T "void *" ""
T.__init__
"""),
("m.T", """
module m
class m.T "void *" ""
@classmethod
m.T.__new__
"""),
("m.T.C", """
module m
class m.T "void *" ""
class m.T.C "void *" ""
m.T.C.__init__
"""),
)
for name, code in dataset:
with self.subTest(name=name, code=code):
block = self.parse(code)
func = block.signatures[-1]
self.assertEqual(func.fulldisplayname, name)

def test_fulldisplayname_meth(self):
dataset = (
("func", "func"),
("m.func", """
module m
m.func
"""),
("T.meth", """
class T "void *" ""
T.meth
"""),
("m.T.meth", """
module m
class m.T "void *" ""
m.T.meth
"""),
("m.T.C.meth", """
module m
class m.T "void *" ""
class m.T.C "void *" ""
m.T.C.meth
"""),
)
for name, code in dataset:
with self.subTest(name=name, code=code):
block = self.parse(code)
func = block.signatures[-1]
self.assertEqual(func.fulldisplayname, name)

def test_depr_star_invalid_format_1(self):
block = """
module foo
Expand Down
13 changes: 10 additions & 3 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2682,9 +2682,16 @@ def displayname(self) -> str:

@functools.cached_property
def fulldisplayname(self) -> str:
if isinstance(self.module, Module):
return f"{self.module.name}.{self.displayname}"
return self.displayname
parent: Class | Module | Clinic | None
if self.kind.new_or_init:
parent = getattr(self.cls, "parent", None)
else:
parent = self.parent
name = self.displayname
while isinstance(parent, (Module, Class)):
name = f"{parent.name}.{name}"
parent = parent.parent
return name

@property
def render_parameters(self) -> list[Parameter]:
Expand Down