Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to annotation type?
#5
I finally made it using typing.overload:
@overload
def func(a: AnyStr, *b: AnyStr) -> Tuple[Optional[AnyStr], AnyStr]:
    ...

@overload
def func(a: AnyStr, *b: AValue) -> Tuple[Optional[AValue], AnyStr]:
    ...

@overload
def func(a: AnyStr, *b: Union[AValue, AnyStr]) -> Tuple[Union[AValue, AnyStr, None], AnyStr]:
    ...

def func(a: AnyStr, *b: Union[AValue, AnyStr]) -> Tuple[Union[AValue, AnyStr, None], AnyStr]:
    for _b in b:
      if isinstance(_b, AValue):
        # ..... some code convert _b into AnyStr (_tb) that match a
      else:
        _tb = _b
      if a.startswith(_tb):
        return (_b, a.removeprefix(_tb))
    return (None, a)
Reply


Messages In This Thread
How to annotation type? - by gamecss - May-25-2023, 03:28 AM
RE: How to annotation type? - by snippsat - May-25-2023, 10:47 AM
RE: How to annotation type? - by gamecss - May-25-2023, 12:26 PM
RE: How to annotation type? - by snippsat - May-25-2023, 03:02 PM
RE: How to annotation type? - by gamecss - Jul-27-2023, 03:03 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Decorators @ annotation drcl 3 1,574 Feb-24-2024, 06:12 AM
Last Post: Gribouillis
  How to extract and label audio using timestamp annotation Mergorine 0 4,556 Nov-30-2020, 04:44 PM
Last Post: Mergorine
  Type hinting - return type based on parameter micseydel 2 3,180 Jan-14-2020, 01:20 AM
Last Post: micseydel
  Function Annotation got NameError: name 'xxx' is not defined Lance 6 7,724 Oct-23-2019, 03:13 AM
Last Post: Lance

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020