Skip to content

Commit

Permalink
Bump version to 2024.09.11 and add changelog
Browse files Browse the repository at this point in the history
Also update docs

PiperOrigin-RevId: 673343897
  • Loading branch information
frigus02 authored and copybara-github committed Sep 11, 2024
1 parent 2f27919 commit dbf678c
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 8 deletions.
43 changes: 43 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
Version 2024.09.11:

Updates:
* Basic support for Python 3.12.

With this release you can run pytype with Python 3.12. But pytype has no
support for any new features added in Python 3.12.

Look out for type checking changes caused by different bytecode emit:
* dict/list/set comprehensions are type checked 1 level deeper.
* Errors after `if` statements can be printed differently.

* Add support for pickled pyi files in merge_pyi.py.

* Several performance improvements.

* Stop validating imports map. Pytype used to validate that each file in an
import map exists. This has proved too costly, especially on network file
systems. Pytype now assumes import maps specified via --imports_info are
correct.

* Add support for flag files (required for Bazel workers).

* Change the format of errors printed to the console.

Errors now also include the column number and a code snippet, which highlights
the part that's broken.

Old:
File "test.py", line 4, in foo: unsupported operand type(s) for +: str and int [unsupported-operands]
Function __add__ on str expects str
New:
test.py:4:10: error: in foo: unsupported operand type(s) for +: str and int [unsupported-operands]
Function __add__ on str expects str
print(arg + 3)
~~~~~~~

Bug fixes:
* Add type stub for `aiter()`.
* Don't include deleted top-level variables in module types.
* Don't crash when a Generic subtype uses a TypeVar differently.
* Fix type inference for `iter(func, None)`.

Version 2024.04.11:

Updates:
Expand Down
22 changes: 20 additions & 2 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ class Person(object):
...
```

Alternatively you can add a `__future__.annotations` import to reference the
type without quotes:

```python
from __future__ import annotations

class Person(object):
def CreatePerson(name: str) -> Person: # no quotes needed
...
```

Note: This import enables [PEP 563](https://www.python.org/dev/peps/pep-0563/),
a previously accepted PEP that has since been superseded by
[PEP 649](https://peps.python.org/pep-0649/). PEP 563's behavior will eventually
be deprecated and removed. However, as of May 2023, a `__future__` import for
PEP 649 is not yet available, so enabling PEP 563 is the best way to avoid
quoted types.

## I'm dynamically populating a class / module using `setattr` or by modifying `locals()` / `globals()`. Now pytype complains about missing attributes or module members. How do I fix this?

Add `_HAS_DYNAMIC_ATTRIBUTES = True` to your class or module.
Expand Down Expand Up @@ -157,14 +175,14 @@ the analysis:
instance of its type:

<!-- bad -->
```python
```python
# Depending on the size of the dictionary and the complexity of the contents,
# pytype may time out analyzing it.
MY_HUGE_DICT = {...}
```

<!-- good -->
```python
```python
from typing import Any, Mapping
# Pytype can use the type annotation rather than inferring a type from the
# value, considerably speeding up analysis. Replace `Any` with more precise
Expand Down
5 changes: 3 additions & 2 deletions docs/pragmas.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ the pytype team if you have any questions or advanced use cases you think a
pragma would help with.

<!--ts-->

* [Pragmas](#pragmas)
* [cache-return](#cache-return)

<!-- Created by https://github.com/ekalinin/github-markdown-toc -->
<!-- Added by: mdemello, at: Tue Mar 5 12:02:15 PM PST 2024 -->
<!-- Added by: jankuehle, at: Wed Sep 11 11:06:46 AM UTC 2024 -->

<!--te-->

Expand Down
6 changes: 3 additions & 3 deletions docs/typing_faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ One somewhat surprising behaviour is illustrated by the following snippet:

```python
xs = [1, 2, 3]
reveal_type(xs) # => List[int]
reveal_type(xs) # => list[int]
xs.append('hello') # no error!
reveal_type(xs) # => List[int | str]
reveal_type(xs) # => list[int | str]
```

Given that `xs` is correctly inferred as `List[int]` in line 2, it could be
Expand All @@ -58,7 +58,7 @@ Explicitly annotating xs with a type will indeed raise a
`container-type-mismatch` error:

```python
xs: List[int] = [1, 2, 3]
xs: list[int] = [1, 2, 3]
xs.append('hello') # ! container-type-mismatch
```

Expand Down
2 changes: 1 addition & 1 deletion pytype/__version__.py
Original file line number Diff line number Diff line change