Skip to content

Commit bc4ea04

Browse files
committed
project: update readme and pull request template
1 parent 4f8a7f2 commit bc4ea04

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

.github/PULL_REQUEST_TEMPLATE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Please include an amongus reference in this PR.
1+
![image](https://github.com/KotlinIsland/basedmypy/blob/master/.github/pull_request.png?raw=true)

.github/pull_request.png

137 KB
Loading

README.md

+35-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ Based features include:
2424
- Support for `Intersection` types
2525
- Default return type of `None` instead of `Any`
2626
- Generic `TypeVar` bounds
27+
- Based type-guards
2728
- Infer parameter type from default value
2829
- Infer overload types
2930
- Bare literals
3031
- Tuple literal types
3132

32-
See the [features](#features) for a more information.
33+
See the [features](#features) for more information, or [the docs](https://kotlinisland.github.io/basedmypy/based_features.html) for a comprehensive list.
3334

3435
## Usage
3536

@@ -49,10 +50,13 @@ Basedmypy is installed as an alternative to, and in place of, the `mypy` install
4950

5051
## Features
5152

52-
Have you ever tried to use Pythons type system and thought to yourself "This doesn't seem based"?
53+
Have you ever tried to use Python's type system and thought to yourself "This doesn't seem based"?
5354

5455
Well fret no longer as basedmypy has got you covered!
5556

57+
You can find a comprehensive list in [the docs](https://kotlinisland.github.io/basedmypy/based_features.html).
58+
59+
5660
### Baseline
5761

5862
Basedmypy has baseline, baseline is based! It allows you to adopt new strictness or features
@@ -145,6 +149,35 @@ reveal_type(foo(["based"], "mypy")) # N: Revealed type is "list[str]"
145149
reveal_type(foo({1, 2}, 3)) # N: Revealed type is "set[int]"
146150
```
147151

152+
### Based type-guards
153+
154+
Type-guards have been re-designed from the ground up:
155+
156+
```py
157+
# The target parameter of the typeguard can be specified
158+
def guard(name: str, x: object) -> x is int: ...
159+
160+
# impossible type-guards show an error
161+
def bad(x: str) -> x is int: ... # error: A type-guard's type must be assignable to its parameter's type. (guard has type "int", parameter has type "str")
162+
163+
class A: ...
164+
class B: ...
165+
def is_b(x: object) -> x is B: ...
166+
167+
x = A()
168+
assert is_b(x)
169+
# type-guards narrow instead of resetting the type
170+
reveal_type(x) # A & B
171+
172+
# type-guards work on instance parameters
173+
class Foo:
174+
def guard(self) -> self is int: ...
175+
176+
f = Foo()
177+
assert f.guard()
178+
reveal_type(f) # Foo & int
179+
```
180+
148181
### Overload Implementation Inference
149182

150183
The types in overload implementations (including properties) can be inferred:

0 commit comments

Comments
 (0)