mirror of
https://github.com/github/codeql.git
synced 2026-04-03 14:18:17 +02:00
Adds `hasOverloadDecorator` as a predicate on functions. It looks for decorators called `overload` or `something.overload` (usually `typing.overload` or `t.overload`). These are then filtered out in the predicates that (approximate) resolving methods according to the MRO. As the test introduced in the previous commit shows, this removes the spurious resolutions we had before.
40 lines
846 B
Python
40 lines
846 B
Python
import typing
|
|
|
|
|
|
class OverloadedInit:
|
|
@typing.overload
|
|
def __init__(self, x: int) -> None: ...
|
|
|
|
@typing.overload
|
|
def __init__(self, x: str, y: str) -> None: ...
|
|
|
|
def __init__(self, x, y=None):
|
|
pass
|
|
|
|
OverloadedInit(1) # $ init=OverloadedInit.__init__:11
|
|
OverloadedInit("a", "b") # $ init=OverloadedInit.__init__:11
|
|
|
|
|
|
from typing import overload
|
|
|
|
|
|
class OverloadedInitFromImport:
|
|
@overload
|
|
def __init__(self, x: int) -> None: ...
|
|
|
|
@overload
|
|
def __init__(self, x: str, y: str) -> None: ...
|
|
|
|
def __init__(self, x, y=None):
|
|
pass
|
|
|
|
OverloadedInitFromImport(1) # $ init=OverloadedInitFromImport.__init__:28
|
|
OverloadedInitFromImport("a", "b") # $ init=OverloadedInitFromImport.__init__:28
|
|
|
|
|
|
class NoOverloads:
|
|
def __init__(self, x):
|
|
pass
|
|
|
|
NoOverloads(1) # $ init=NoOverloads.__init__:36
|