Skip to content

Commit

Permalink
project: update readme and pull request template
Browse files Browse the repository at this point in the history
  • Loading branch information
KotlinIsland committed Oct 16, 2023
1 parent 4f8a7f2 commit 00d22ec
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Please include an amongus reference in this PR.
![](pull_request.png)
Binary file added .github/pull_request.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ Based features include:
- Support for `Intersection` types
- Default return type of `None` instead of `Any`
- Generic `TypeVar` bounds
- Based type-guards
- Infer parameter type from default value
- Infer overload types
- Bare literals
- Tuple literal types

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

## Usage

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

## Features

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

Well fret no longer as basedmypy has got you covered!

You can find a comprehensive list in [the docs](https://kotlinisland.github.io/basedmypy/based_features.html).


### Baseline

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

### Based type-guards

Type-guards have been re-designed from the ground up:

```py
# The target parameter of the typeguard can be specified
def guard(name: str, x: object) -> x is int: ...

# impossible type-guards show an error
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")

class A: ...
class B: ...
def is_b(x: object) -> x is B: ...

x = A()
assert is_b(x)
# type-guards narrow instead of resetting the type
reveal_type(x) # A & B

# type-guards work on instance parameters
class Foo:
def guard(self) -> self is int: ...

f = Foo()
assert f.guard()
reveal_type(f) # Foo & int
```

### Overload Implementation Inference

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

0 comments on commit 00d22ec

Please sign in to comment.