mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-107883: Argument Clinic: Handle full module/class path in Function.fulldisplayname (#107884)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
bf707749e8
commit
ee40b3e20d
2 changed files with 64 additions and 3 deletions
|
@ -1513,6 +1513,60 @@ class ClinicParserTest(TestCase):
|
||||||
with self.subTest(block=block):
|
with self.subTest(block=block):
|
||||||
self.expect_failure(block, err)
|
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):
|
def test_depr_star_invalid_format_1(self):
|
||||||
block = """
|
block = """
|
||||||
module foo
|
module foo
|
||||||
|
|
|
@ -2682,9 +2682,16 @@ class Function:
|
||||||
|
|
||||||
@functools.cached_property
|
@functools.cached_property
|
||||||
def fulldisplayname(self) -> str:
|
def fulldisplayname(self) -> str:
|
||||||
if isinstance(self.module, Module):
|
parent: Class | Module | Clinic | None
|
||||||
return f"{self.module.name}.{self.displayname}"
|
if self.kind.new_or_init:
|
||||||
return self.displayname
|
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
|
@property
|
||||||
def render_parameters(self) -> list[Parameter]:
|
def render_parameters(self) -> list[Parameter]:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue