Skip to content

Commit f9a7fb9

Browse files
committed
fix
1 parent 5da1312 commit f9a7fb9

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

pycroscope/name_check_visitor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6100,7 +6100,7 @@ def _extract_definite_value(val: Value) -> Optional[bool]:
61006100

61016101

61026102
try:
6103-
from pydantic import BaseModel
6103+
from pydantic import BaseModel # static analysis: ignore[import_failed]
61046104
except ImportError:
61056105

61066106
def _is_safe_pydantic_class(typ: type) -> bool:

pycroscope/test_annotations.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ def rgx(m: Match[str], p: Pattern[bytes]) -> None:
7575
assert_is_value(p, GenericValue(_Pattern, [TypedValue(bytes)]))
7676
assert_is_value(m, GenericValue(_Match, [TypedValue(str)]))
7777

78+
@skip_before((3, 10))
79+
@assert_passes()
80+
def test_union_as_an_annotation(self):
81+
from types import UnionType
82+
83+
def capybara(x: UnionType) -> None:
84+
pass
85+
86+
def caller() -> None:
87+
capybara(1) # E: incompatible_argument
88+
capybara(int | str)
89+
7890
@assert_passes()
7991
def test_generic(self):
8092
from typing import Any, List

pycroscope/typeshed.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ def get_bases_for_value(self, val: Value) -> Optional[list[Value]]:
330330
return [GenericValue(Collection, (TypeVarValue(T_co),))]
331331
if typ is collections.abc.Callable:
332332
return None
333+
if sys.version_info >= (3, 10) and typ is types.UnionType:
334+
return None
333335
# In 3.11 it's named EnumType and EnumMeta is an alias, but the
334336
# stubs have it the other way around. We can't deal with that for now.
335337
if typ is EnumMeta:
@@ -343,7 +345,12 @@ def get_bases_for_value(self, val: Value) -> Optional[list[Value]]:
343345
return [GenericValue(Collection, (TypeVarValue(T_co),))]
344346
elif fq_name == "contextlib.AbstractContextManager":
345347
return [GenericValue(Protocol, (TypeVarValue(T_co),))]
346-
elif fq_name in ("typing.Callable", "collections.abc.Callable"):
348+
elif fq_name in (
349+
"typing.Callable",
350+
"collections.abc.Callable",
351+
"typing.Union",
352+
"types.UnionType",
353+
):
347354
return None
348355
elif is_typing_name(fq_name, "TypedDict"):
349356
return [

0 commit comments

Comments
 (0)