Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,23 @@ repos:
)$
priority: 1

# Priority 2: blacken-docs runs after markdownlint-fix (both modify markdown).
- repo: https://github.com/adamchainz/blacken-docs
rev: 1.20.0
# Priority 2: ruffen-docs runs after markdownlint-fix (both modify markdown).
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.1
hooks:
- id: blacken-docs
language: python # means renovate will also update `additional_dependencies`
args: ["--pyi", "--line-length", "130"]
files: '^crates/.*/resources/mdtest/.*\.md'
exclude: |
(?x)^(
.*?invalid(_.+)*_syntax\.md
)$
additional_dependencies:
- black==26.1.0
- id: ruff-format
name: mdtest format
args:
[
"--preview",
"--line-length",
"130",
"--extension",
"py:pyi,python:pyi",
]
types_or: [markdown]
files: '^crates/.*/resources/mdtest/.*\.md$'
pass_filenames: true
priority: 2

# `actionlint` hook, for verifying correct syntax in GitHub Actions workflows.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

```pyi
def get_foo() -> Foo: ...

class Foo: ...
```

Expand Down Expand Up @@ -256,7 +257,6 @@ Forward references in class keyword arguments are allowed in stub files.

```pyi
class Foo(metaclass=SomeMeta): ...

class SomeMeta(type): ...
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ bound at `C.f`.
from typing import Self
from ty_extensions import generic_context

class C[T]():
class C[T](): # fmt:skip
def f(self: Self):
def b(x: Self):
reveal_type(x) # revealed: Self@f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def f1(
h: """int""",
# error: [byte-string-type-annotation] "Type expressions cannot use bytes literal"
i: "b'int'",
):
): # fmt:skip
reveal_type(a) # revealed: Unknown
reveal_type(b) # revealed: Unknown
reveal_type(c) # revealed: Unknown
Expand All @@ -104,7 +104,7 @@ def f1(
```py
from typing import Literal

def f(v: Literal["a", r"b", b"c", "d" "e", "\N{LATIN SMALL LETTER F}", "\x67", """h"""]):
def f(v: Literal["a", r"b", b"c", "d" "e", "\N{LATIN SMALL LETTER F}", "\x67", """h"""]): # fmt:skip
reveal_type(v) # revealed: Literal["a", "b", "de", "f", "g", "h", b"c"]
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ reveal_type(x) # revealed: Foo

```pyi
x: int = 1
reveal_type(x) # revealed: Literal[1]
reveal_type(x) # revealed: Literal[1]
```

## Annotations influence generic call inference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def _(flag: bool):
if flag:
def __iadd__(self, other: int) -> str:
return "Hello, world!"

else:
def __iadd__(self, other: int) -> int:
return 42
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ class Foo(ABC):
@classmethod
@abstractmethod
def classmethod(cls) -> int: ...

@staticmethod
@abstractmethod
def staticmethod() -> int: ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def _(flag: bool) -> None:
class Foo:
if flag:
def __new__(cls, x: int): ...

else:
def __new__(cls, x: int, y: int = 1): ...

Expand Down Expand Up @@ -320,6 +321,7 @@ def _(flag: bool) -> None:
class Foo:
if flag:
def __init__(self, x: int): ...

else:
def __init__(self, x: int, y: int = 1): ...

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def _(flag: bool):
if flag:
def __getitem__(self, key: int) -> str:
return str(key)

else:
def __getitem__(self, key: int) -> bytes:
return bytes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ class SomeEnum(Enum):
B = 2
C = 3


class A: ...
class B: ...
class C: ...
Expand Down Expand Up @@ -1494,19 +1493,16 @@ class B: ...
def f1(x: int) -> A: ...
@overload
def f1(x: Any, y: Any) -> A: ...

@overload
def f2(x: int) -> A: ...
@overload
def f2(x: Any, y: Any) -> B: ...

@overload
def f3(x: int) -> A: ...
@overload
def f3(x: Any, y: Any) -> A: ...
@overload
def f3(x: Any, y: Any, *, z: str) -> B: ...

@overload
def f4(x: int) -> A: ...
@overload
Expand Down Expand Up @@ -1550,14 +1546,12 @@ def f1(x1: T1, x2: T2, /) -> tuple[T1, T2]: ...
def f1(x1: T1, x2: T2, x3: T3, /) -> tuple[T1, T2, T3]: ...
@overload
def f1(*args: Any) -> tuple[Any, ...]: ...

@overload
def f2(x1: T1) -> tuple[T1]: ...
@overload
def f2(x1: T1, x2: T2) -> tuple[T1, T2]: ...
@overload
def f2(*args: Any, **kwargs: Any) -> tuple[Any, ...]: ...

@overload
def f3(x: T1) -> tuple[T1]: ...
@overload
Expand Down
2 changes: 2 additions & 0 deletions crates/ty_python_semantic/resources/mdtest/call/union.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def _(flag: bool):
if flag:
def f() -> int:
return 1

else:
def f() -> str:
return "foo"
Expand Down Expand Up @@ -859,6 +860,7 @@ def _(flag: bool):
if flag:
def f(x: T) -> int:
return 1

else:
def f(x: dict[str, int]) -> int:
return 1
Expand Down
2 changes: 2 additions & 0 deletions crates/ty_python_semantic/resources/mdtest/class/super.md
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,10 @@ def coinflip() -> bool:
def f():
if coinflip():
class A: ...

else:
class A: ...

super(A, A()) # error: [invalid-super-argument]
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ class NotBoolable:

# error: [unsupported-bool-conversion] "Boolean conversion is not supported for type `NotBoolable`"
if NotBoolable():
...
pass
# error: [unsupported-bool-conversion] "Boolean conversion is not supported for type `NotBoolable`"
elif NotBoolable():
...
pass
```
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ from dataclasses import field

@dataclass_transform(kw_only_default=True)
def create_model(*, kw_only: bool = True): ...

@create_model()
class A:
name: str
Expand Down Expand Up @@ -282,6 +283,7 @@ from typing import dataclass_transform

@dataclass_transform(frozen_default=True)
def create_model(*, frozen: bool = True): ...

@create_model()
class ImmutableModel:
name: str
Expand Down Expand Up @@ -339,6 +341,7 @@ from typing import dataclass_transform

@dataclass_transform(eq_default=True, order_default=False, kw_only_default=True, frozen_default=True)
def create_model(*, eq: bool = True, order: bool = False, kw_only: bool = True, frozen: bool = True): ...

@create_model(eq=False, order=True, kw_only=False, frozen=False)
class OverridesAllParametersModel:
name: str
Expand Down Expand Up @@ -367,6 +370,7 @@ from typing import dataclass_transform

@dataclass_transform(frozen_default=True)
def default_frozen_model(*, frozen: bool = True, order: bool = False): ...

@default_frozen_model()
class Frozen:
name: str
Expand Down Expand Up @@ -466,6 +470,7 @@ from typing import dataclass_transform

@dataclass_transform(frozen_default=True)
def frozen_model(*, frozen: bool = True): ...

@frozen_model()
class FrozenWithOverrides:
x: int
Expand Down Expand Up @@ -497,6 +502,7 @@ from typing import dataclass_transform

@dataclass_transform()
def ordered_model(*, order: bool = False): ...

@ordered_model(order=True)
class OrderedWithOverrides:
x: int
Expand Down Expand Up @@ -652,6 +658,7 @@ reveal_type(alice.age) # revealed: int | None
from typing_extensions import dataclass_transform, Any

def fancy_field(*, init: bool = True, kw_only: bool = False, alias: str | None = None) -> Any: ...

@dataclass_transform(field_specifiers=(fancy_field,))
class FancyMeta(type):
def __new__(cls, name, bases, namespace):
Expand Down Expand Up @@ -680,6 +687,7 @@ reveal_type(alice.age) # revealed: int | None
from typing_extensions import dataclass_transform, Any

def fancy_field(*, init: bool = True, kw_only: bool = False, alias: str | None = None) -> Any: ...

@dataclass_transform(field_specifiers=(fancy_field,))
class FancyBase:
def __init_subclass__(cls):
Expand Down Expand Up @@ -763,6 +771,7 @@ from typing import Any
from typing_extensions import dataclass_transform

def field(**kwargs: Any) -> Any: ...

@dataclass_transform(field_specifiers=(field,))
class ModelMeta(type): ...

Expand Down Expand Up @@ -790,6 +799,7 @@ from typing import Any
from typing_extensions import dataclass_transform

def field(**kwargs: Any) -> Any: ...

@dataclass_transform(field_specifiers=(field,))
class ModelBase: ...

Expand Down Expand Up @@ -1094,6 +1104,7 @@ class InvalidKWOnlyDefaultModel:
from typing_extensions import Any, dataclass_transform

def field(*, init: bool = True, kw_only: bool = False, default: Any = ...) -> Any: ...

@dataclass_transform(field_specifiers=(field,))
class ModelMeta(type): ...

Expand Down Expand Up @@ -1140,6 +1151,7 @@ class InvalidKWOnlyDefaultModel(KWOnlyDefaultModelBase):
from typing_extensions import Any, dataclass_transform

def field(*, init: bool = True, kw_only: bool = False, default: Any = ...) -> Any: ...

@dataclass_transform(field_specifiers=(field,))
class ModelBase:
def __init_subclass__(cls):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ from ty_extensions import TypeOf
class SomeClass: ...

def some_function() -> None: ...

@dataclass
class D:
function_literal: TypeOf[some_function]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ from datetime import datetime

class UnawaitableUnion:
if datetime.today().weekday() == 6:

def __await__(self) -> typing.Generator[typing.Any, None, None]:
yield
else:

else:
def __await__(self) -> int:
return 5

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ python-version = "3.10"
match 2:
# error: [invalid-syntax] "mapping pattern checks duplicate key `"x"`"
case {"x": 1, "x": 2}:
...
pass
```

## Duplicate `match` class attribute
Expand Down Expand Up @@ -224,7 +224,7 @@ def func():

def gen():
# error: [invalid-syntax] "Starred expression cannot be used here"
yield * [1, 2, 3]
yield *[1, 2, 3]

# error: [invalid-syntax] "Starred expression cannot be used here"
for *x in range(10):
Expand Down Expand Up @@ -340,10 +340,10 @@ def _():

# error: [invalid-syntax] "`async for` outside of an asynchronous function"
async for _ in elements(1):
...
pass
# error: [invalid-syntax] "`async with` outside of an asynchronous function"
async with elements(1) as x:
...
pass
# error: [invalid-syntax] "asynchronous comprehension outside of an asynchronous function"
[x async for x in elements(1)]
```
Expand Down
Loading
Loading