Based static typing for Python
Project description
Ever tried to use pythons type system and thought to yourself “This doesn’t seem based”.
Well fret no longer as basedmypy got you covered!
Baseline
Basedmypy has baseline, baseline is based! It allows you to adopt new strictness or features without the burden of fixing up every usage, just save all current errors to the baseline file and deal with them later.
def foo(a):
print(a)
> mypy test.py
error: missing typehints !!!!!
Epic fail bro!
> mypy --write-baseline test.py
test.py:1:1: error: Function is missing a type annotation for one or more arguments [no-untyped-def]
Baseline successfully written to .mypy/baseline.json
> mypy test.py
Success: no issues found in 1 source file
Then on subsequent runs the existing errors will be filtered out.
def foo(a):
print(a)
def bar(b: str, c: int) -> bool:
return b + c
> mypy test.py
test.py:4:5: error: Returning Any from function declared to return "bool" [no-any-return]
test.py:4:16: error: Unsupported operand types for + ("str" and "int") [operator]
Found 2 errors in 1 file (checked 1 source file)
Intersection Types
Using the & operator or basedtyping.Intersection you can denote intersection types.
class Growable(ABC, Generic[T]):
@abstractmethod
def add(self, item: T): ...
class Resettable(ABC):
@abstractmethod
def reset(self): ...
def f(x: Resettable & Growable[str]):
x.reset()
x.add("first")
Type Joins
Mypy joins types like so:
a: int
b: str
reveal_type(a if bool() else b) # Revealed type is "builtins.object"
Basedmypy joins types into unions instead:
a: int
b: str
reveal_type(a if bool() else b) # Revealed type is "int | str"
Bare Literals
Literal is so cumbersome! just use a bare literal instead.
class Color(Enum):
RED = auto()
a: 1 | 2
b: True | Color.RED
Default Return Type
With the default_return option, the default return type of functions becomes None instead of Any.
def f(name: str):
print(f"Hello, {name}!")
reveal_type(f) # (str) -> None
Nested TypeVars
With nested TypeVars you are able to have functions with polymorphic generic parameters.
E = TypeVar("E")
I = TypeVar("I", bound=Iterable[E])
def foo(i: I, e: E) -> I:
assert e not in i
return i
reveal_type(foo(["based"], "mypy")) # N: Revealed type is "list[str]"
reveal_type(foo({1, 2}, 3)) # N: Revealed type is "set[int]"
Overload Implementation Inference
Specifying types in overload implementations is completely redundant! basedmypy will infer them.
@overload
def f(a: int) -> str: ...
@overload
def f(a: str) -> int: ...
def f(a):
reveal_type(a) # int | str
return None # error: expected str | int
class A:
@property
def foo(self) -> int: ...
@foo.setter
def foo(self, value): ... # no need for annotations
Infer Function Parameters
Infer the type of a function parameter from it’s default value.
def f(a=1, b=True):
reveal_type((a, b)) # (int, bool)
Better Types in Messages
T = TypeVar("T", bound=int)
def f(a: T, b: list[str | 1 | 2]) -> Never:
reveal_type((a, b))
reveal_type(f)
Mypy shows:
Revealed type is "Tuple[T`-1, Union[builtins.str, Literal[1], Literal[2]]]" Revealed type is "def [T <: builtins.int] (a: T`-1, b: Union[builtins.str, Literal[1], Literal[2]]) -> <nothing>"
Basedmypy shows:
Revealed type is "(T@f, str | 1 | 2)" Revealed type is "def [T: int] (a: T, b: str | 1 | 2) -> Never"
Ignore Unused Type Ignores
In code that is targeting multiple versions of python or multiple platforms it is difficult to work with type: ignore comments and use the warn_unused_ignore option.
The unused-ignore error code can be used for this situation.
if sys.platform != "linux":
foo() # type: ignore[misc, unused-ignore]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for basedmypy-1.8.0rc1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f54ffb09a5dd790354eeb16ff1c6a5fcb96f1425eaf4af659fa455c0c97f4b8 |
|
MD5 | 20680553051bf8728f028f875b4ca04a |
|
BLAKE2b-256 | 7793de18826da8b189d7a9ea4e8183fd9ac892ceee15e5e37bf2727f332632a3 |
Hashes for basedmypy-1.8.0rc1-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 106eb0243631e6d0ab4746434fc115dc2066f76b017eb9323970f41d22d88fb7 |
|
MD5 | f676683fa4eebb7ce240591694225158 |
|
BLAKE2b-256 | 927413907c289326f9bd0f4731b00c11601a494b9e7b362a7a143484889e6296 |
Hashes for basedmypy-1.8.0rc1-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37ae8fb06727ef303d4f3bba506171389014e51249d509e4f519c878d1804ca1 |
|
MD5 | b2ea8059245ce737a1a08bcbdccc370d |
|
BLAKE2b-256 | 8bece1f07b5a5149d30f6fc7730dc443d7acefb014b96d1d7a0356166492a4f2 |
Hashes for basedmypy-1.8.0rc1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa276fe20955f26463fa303185c03606f5c3f8c38ee4b8729ac8d4fa468d7602 |
|
MD5 | 37d7696908dc813443eb0be89e38f915 |
|
BLAKE2b-256 | 1602600f899c29a31a8f22dfd2a3944163fb4a47d6a7de024f0c49bd2e5427be |
Hashes for basedmypy-1.8.0rc1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77eac3e7318f67a3ce19f2736374791885add985b24d21a924704840bd979986 |
|
MD5 | 22a6edcddc9b8398017a06a110640aab |
|
BLAKE2b-256 | 7e359494bb86ebab1d04553086b92cfef0b0a908cbd74ad671424cf57154bdba |
Hashes for basedmypy-1.8.0rc1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27d6ec82ac1e46d3758e0f7956459f025fa56d67bb9011b5021a609dac9b05d8 |
|
MD5 | 343b1e30dd3ed59a063ce6a5af678a95 |
|
BLAKE2b-256 | 2de5892edc0386e6b029721d1e81f792f890e3123ca29d17af7b9086deeaf9e6 |
Hashes for basedmypy-1.8.0rc1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d8de98b8e006612ff8c8c2a25c8a6b947f4e0ad21688b4f1eedc0a385c7e6c1 |
|
MD5 | 8f7e53b87f88df215f9bd8df062620d5 |
|
BLAKE2b-256 | a0cc7505eaf2b2c474b06a713fbeb209ba21db143598f2fbf6a65c1c0b8d11fe |
Hashes for basedmypy-1.8.0rc1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb7290cfe2b3f11b8db77e541fe8c054781cd9f84632ef9a457f88a605b329c7 |
|
MD5 | 41220d9cf5c3a93b4744ac9ccd782b1d |
|
BLAKE2b-256 | 5392f505f76fdc4070ac97ca1515ddae84ec54258a101f4fb4bdc260a3d9103e |
Hashes for basedmypy-1.8.0rc1-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 268bcd4387fc149cd289d5bf7ea411f45a88e1e6271e07b38126e81bcc0b3c35 |
|
MD5 | 5866c53046edc0ca2290004c2d8cae29 |
|
BLAKE2b-256 | 73e47c8612747f9a405fff12ea751510044c3945dc048008028db42c920e6da1 |
Hashes for basedmypy-1.8.0rc1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54bb3b8814d760e7ec30723582da571a80914c09e07ce46d9f53519833839d77 |
|
MD5 | 0bd5ac5c8afc3fbd92d64e301dedd3f7 |
|
BLAKE2b-256 | e0f6f491b783e129bf9d8e3792dd20d50902c14ca13c2a0d60178907e29215d1 |
Hashes for basedmypy-1.8.0rc1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6f24cc2855ee2ce8eb165557510e1613cb16c2eb0e0468817fb6239148fbb26 |
|
MD5 | 5e9fcb6dfdb624efbeec14ae2c2ee4bc |
|
BLAKE2b-256 | 0edf97b1b210ed188cf9a118d7ec7791fa8b531cb199cde3fb756b1ff26d245b |
Hashes for basedmypy-1.8.0rc1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46a19adac174a2ba87c1437575e368a552a946794fee434908a8035067a52b91 |
|
MD5 | 701f74a834bee1027a452efb9abd9b59 |
|
BLAKE2b-256 | 19d25816b98357aca29d6b7acdda375e163cff4f655cf9ff7839f150cf6c21f0 |
Hashes for basedmypy-1.8.0rc1-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f630df4e0b684a91259f22111a851b9e49f1572ae50124ea39dd7b88588294cb |
|
MD5 | b8d1d56ada7120699985b865f93fc645 |
|
BLAKE2b-256 | 15fe50f5be5855633918a6d34e61f06db67604714d3d4a116890721dd9e1790f |
Hashes for basedmypy-1.8.0rc1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a1161a5226d28cd058d635f933019c68075c7a2e29aa6e08473e121bb24f7b8 |
|
MD5 | 30be0df3ec385fbf3258f10b37be862c |
|
BLAKE2b-256 | ba1cd650cde4fc85d9e7d908c9d6d65f66ddabae0845bfb0f3a528b9af7c2f46 |
Hashes for basedmypy-1.8.0rc1-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb7c074dcaa896e88fd514c0a803e01fe36e4cf90b273bdd8cfd7b4f0e6e9fc2 |
|
MD5 | b2f8ab714e71e7b1ec79fdf8e9f90e3c |
|
BLAKE2b-256 | d1d0505802d7403997f3609030e2831e6c1b020d7f0edde088f322d4af7ca951 |
Hashes for basedmypy-1.8.0rc1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75eec448c0eef5bb40f6e9b40e6a3f9662484a31e6944fa9644cfef7c6680133 |
|
MD5 | 4dd04134580bb2ae18173199d017f279 |
|
BLAKE2b-256 | aaa95c28fab8b15f401e1df24ddea97bb8e62013523d03d592df5f5fc39352f3 |
Hashes for basedmypy-1.8.0rc1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3cdab7af13718df4774ae7027314e60c80fd682bb8ffa9d3ba6c51f54156d602 |
|
MD5 | 06c06255b74965627b919ffb78d9791a |
|
BLAKE2b-256 | 8bbcb08a2f2bb15d728796282695e6e57b6458f65af71a936bcf0ecaa8103797 |
Hashes for basedmypy-1.8.0rc1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05b88a13155414f2eecba49e52456da175b88382247b1e06248ee8a4c9e9138d |
|
MD5 | ace3ea6a4a48d9832105507d5c3949c2 |
|
BLAKE2b-256 | 77e6e488ae67ff381280a3db1d4beb7b64e6aac16161a4eb8c7765a69bd4c4b4 |
Hashes for basedmypy-1.8.0rc1-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94dbbfc839157b8eb777c156f0b3608599ccde124c5a87a3da2da5c943e4864c |
|
MD5 | 81d8bbc19cf2b339c872f6fd8295f7f3 |
|
BLAKE2b-256 | e319b8a38bcfa26f02d49668dc650e658f6838db87b5efd1e1f3f6df06d0e269 |
Hashes for basedmypy-1.8.0rc1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebc97b16e503efed25030657df701852c127c22f7a38388b49a99003a1c1396f |
|
MD5 | 28c9bebbd91e771b000c36c185bbcfda |
|
BLAKE2b-256 | c443da8c9b8a423a73b3e0ca321ee55807c93600d68edc3849c0ee6c5535ffd7 |
Hashes for basedmypy-1.8.0rc1-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87be5b0b73eb41fd2a9baa29011ce8c2f3a5bcd57d5f98e655dcfa681aaaecaa |
|
MD5 | 30510b63bbcd9ac67565ee0b71ffca5c |
|
BLAKE2b-256 | bca071891edde613937f16bd3ccef53e47e3d41f6fe3c7433610dc1aad9404d1 |
Hashes for basedmypy-1.8.0rc1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84f01dd89ff9667143f03d48468d6fc8d5411f7ff980f2e056ba1a7c99d9d1b8 |
|
MD5 | abba89065cd3867e5d64076ce79d15f9 |
|
BLAKE2b-256 | cc4aab6b3165af38a52e7e7250f9093ff266e3ed287c416656c3ae60bbd9da27 |
Hashes for basedmypy-1.8.0rc1-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38e0efbc0423c796a5727ce804bf3dd84c344482dd045c5ea9a4bdd24cc6dfcd |
|
MD5 | cd27ad0c751c9e1ee75260b16fdee8a9 |
|
BLAKE2b-256 | 28e6c785ee0e398bc12b0cb4453510b5eaa4bdfd6c41d46b4f300b59cf19ba09 |
Hashes for basedmypy-1.8.0rc1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04ae6ba7447c19487e254c123f124b58cf9ed34e3ab1f5842acf711042ef7102 |
|
MD5 | 98cd50e99b9575cc1cdb151989526f85 |
|
BLAKE2b-256 | f9425f0b1194e981651327287b48f1acf6a6d6d2e3b8144b9d5e5526a0db3038 |
Hashes for basedmypy-1.8.0rc1-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70435df2f9e7326550f40bf2b1eb1c39f81adb1a4fffe3d2d62e4e92de8f8031 |
|
MD5 | b42e78ab803ce0c73e642798eb206592 |
|
BLAKE2b-256 | 46641a67f18d6330cace55bdbed32d20d7395985310fdcd537c15f8a66736cc2 |
Hashes for basedmypy-1.8.0rc1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8896b1b3d6e2eb5eb235a3cb04fba4150bec2a1a7fa7626f0c71ef9228feb5de |
|
MD5 | c4a79b75171c84b79136b7a325b21a83 |
|
BLAKE2b-256 | 7c2c375acb3c81612c74355b08f089674f0d3fe89cb03581212c627833994e48 |
Hashes for basedmypy-1.8.0rc1-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45b287bd9a2089d457fd9d2c80e01b97212cc5f6ffa9f67c687332ee3c0835ed |
|
MD5 | 7786d9ea630a56c8b576a76f0580efba |
|
BLAKE2b-256 | 54455b89fab9e75566a2713581dec6d287ac362e7c70d0b4aa8b1a2b13b6b96d |
Hashes for basedmypy-1.8.0rc1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18cee1419f178fae935aef52a70632632bffe94d118a47958726840ff322af21 |
|
MD5 | 2483a029cc24cea76625dd053d6de67d |
|
BLAKE2b-256 | bb945ef34c2e6bbd5acb495d64f2fbe5bda593d7a6d0312aec18aac36c2337e8 |
Hashes for basedmypy-1.8.0rc1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c1cc30b6106d3a2e43bd6293650f0b5b8d89ebcfe25b86637eacdf4ac7f64f7 |
|
MD5 | 4574507db5cf84314d0dcbbf6195ac92 |
|
BLAKE2b-256 | fc886b07000b7d8790262b1f25ff9244bb0cb7f7fdc6efb849f35686deec5339 |