Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdbfe738

Browse files
authored
gh-104050: Argument clinic: improve typing around adding C converters (#107209)
1 parent3b30931 commitdbfe738

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

‎Tools/clinic/clinic.py‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
NoReturn,
4545
Protocol,
4646
TypeGuard,
47+
TypeVar,
4748
overload,
4849
)
4950

@@ -2647,10 +2648,12 @@ def __getattribute__(self, name: str) -> Any:
26472648
fail("Stepped on a land mine, trying to access attribute "+repr(name)+":\n"+self.__message__)
26482649

26492650

2651+
CConverterClassT=TypeVar("CConverterClassT",bound=type["CConverter"])
2652+
26502653
defadd_c_converter(
2651-
f:type[CConverter],
2654+
f:CConverterClassT,
26522655
name:str|None=None
2653-
)->type[CConverter]:
2656+
)->CConverterClassT:
26542657
ifnotname:
26552658
name=f.__name__
26562659
ifnotname.endswith('_converter'):
@@ -2659,7 +2662,7 @@ def add_c_converter(
26592662
converters[name]=f
26602663
returnf
26612664

2662-
defadd_default_legacy_c_converter(cls):
2665+
defadd_default_legacy_c_converter(cls:CConverterClassT)->CConverterClassT:
26632666
# automatically add converter for default format unit
26642667
# (but without stomping on the existing one if it's already
26652668
# set, in case you subclass)
@@ -2670,16 +2673,19 @@ def add_default_legacy_c_converter(cls):
26702673

26712674
defadd_legacy_c_converter(
26722675
format_unit:str,
2673-
**kwargs
2674-
)->Callable[[ConverterType],ConverterType]:
2676+
**kwargs:Any
2677+
)->Callable[[CConverterClassT],CConverterClassT]:
26752678
"""
26762679
Adds a legacy converter.
26772680
"""
2678-
defclosure(f):
2681+
defclosure(f:CConverterClassT)->CConverterClassT:
2682+
added_f:Callable[...,CConverter]
26792683
ifnotkwargs:
26802684
added_f=f
26812685
else:
2682-
added_f=functools.partial(f,**kwargs)
2686+
# mypy's special-casing for functools.partial
2687+
# can't quite grapple with this code here
2688+
added_f=functools.partial(f,**kwargs)# type: ignore[arg-type]
26832689
ifformat_unit:
26842690
legacy_converters[format_unit]=added_f
26852691
returnf

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp