|
2 | 2 |
|
3 | 3 | ## Next release |
4 | 4 |
|
| 5 | +### Change to enum membership semantics |
| 6 | + |
| 7 | +As per the updated [typing specification for enums](https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members), |
| 8 | +enum members must be left unannotated. |
| 9 | + |
| 10 | +```python |
| 11 | +class Pet(Enum): |
| 12 | + CAT = 1 # Member attribute |
| 13 | + DOG = 2 # Member attribute |
| 14 | + WOLF: int = 3 # New error: Enum members must be left unannotated |
| 15 | + |
| 16 | + species: str # Considered a non-member attribute |
| 17 | +``` |
| 18 | + |
| 19 | +In particular, the specification change can result in issues in type stubs (`.pyi` files), since |
| 20 | +historically it was common to leave the value absent: |
| 21 | + |
| 22 | +```python |
| 23 | +# In a type stub (.pyi file) |
| 24 | + |
| 25 | +class Pet(Enum): |
| 26 | + # Change in semantics: previously considered members, now non-member attributes |
| 27 | + CAT: int |
| 28 | + DOG: int |
| 29 | + |
| 30 | + # Mypy will now issue a warning if it detects this situation in type stubs: |
| 31 | + # > Detected enum "Pet" in a type stub with zero members. |
| 32 | + # > There is a chance this is due to a recent change in the semantics of enum membership. |
| 33 | + # > If so, use `member = value` to mark an enum member, instead of `member: type` |
| 34 | + |
| 35 | +class Pet(Enum): |
| 36 | + # As per the specification, you should now do one of the following: |
| 37 | + DOG = 1 # Member attribute with value 1 and known type |
| 38 | + WOLF = cast(int, ...) # Member attribute with unknown value but known type |
| 39 | + LION = ... # Member attribute with unknown value and unknown type |
| 40 | +``` |
| 41 | + |
| 42 | +Contributed by Terence Honles in PR [17207](https://github.com/python/mypy/pull/17207) and |
| 43 | +Shantanu Jain in PR [18068](https://github.com/python/mypy/pull/18068). |
| 44 | + |
| 45 | +## Mypy 1.13 |
| 46 | + |
| 47 | +We’ve just uploaded mypy 1.13 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)). |
| 48 | +Mypy is a static type checker for Python. You can install it as follows: |
| 49 | + |
| 50 | + python3 -m pip install -U mypy |
| 51 | + |
| 52 | +You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io). |
| 53 | + |
| 54 | +Note that unlike typical releases, Mypy 1.13 does not have any changes to type checking semantics |
| 55 | +from 1.12.1. |
| 56 | + |
| 57 | +### Improved performance |
| 58 | + |
| 59 | +Mypy 1.13 contains several performance improvements. Users can expect mypy to be 5-20% faster. |
| 60 | +In environments with long search paths (such as environments using many editable installs), mypy |
| 61 | +can be significantly faster, e.g. 2.2x faster in the use case targeted by these improvements. |
| 62 | + |
| 63 | +Mypy 1.13 allows use of the `orjson` library for handling the cache instead of the stdlib `json`, |
| 64 | +for improved performance. You can ensure the presence of `orjson` using the `faster-cache` extra: |
| 65 | + |
| 66 | + python3 -m pip install -U mypy[faster-cache] |
| 67 | + |
| 68 | +Mypy may depend on `orjson` by default in the future. |
| 69 | + |
| 70 | +These improvements were contributed by Shantanu. |
| 71 | + |
| 72 | +List of changes: |
| 73 | +* Significantly speed up file handling error paths (Shantanu, PR [17920](https://github.com/python/mypy/pull/17920)) |
| 74 | +* Use fast path in modulefinder more often (Shantanu, PR [17950](https://github.com/python/mypy/pull/17950)) |
| 75 | +* Let mypyc optimise os.path.join (Shantanu, PR [17949](https://github.com/python/mypy/pull/17949)) |
| 76 | +* Make is_sub_path faster (Shantanu, PR [17962](https://github.com/python/mypy/pull/17962)) |
| 77 | +* Speed up stubs suggestions (Shantanu, PR [17965](https://github.com/python/mypy/pull/17965)) |
| 78 | +* Use sha1 for hashing (Shantanu, PR [17953](https://github.com/python/mypy/pull/17953)) |
| 79 | +* Use orjson instead of json, when available (Shantanu, PR [17955](https://github.com/python/mypy/pull/17955)) |
| 80 | +* Add faster-cache extra, test in CI (Shantanu, PR [17978](https://github.com/python/mypy/pull/17978)) |
| 81 | + |
| 82 | +### Acknowledgements |
| 83 | +Thanks to all mypy contributors who contributed to this release: |
| 84 | + |
| 85 | +- Shantanu Jain |
| 86 | +- Jukka Lehtosalo |
| 87 | + |
5 | 88 | ## Mypy 1.12 |
6 | 89 |
|
7 | 90 | We’ve just uploaded mypy 1.12 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)). Mypy is a static type |
|
0 commit comments