Skip to content

Commit

Permalink
Merge branch 'main' into 313
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood authored Jun 10, 2024
2 parents 13ef45b + 078bc84 commit 8122d4f
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 95 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
Expand All @@ -47,7 +47,7 @@ jobs:
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: curl -LsSf https://astral.sh/uv/install.sh | sh
Expand All @@ -66,7 +66,7 @@ jobs:
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install pypa/build
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/typeshed_primer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
repository: python/typeshed
path: typeshed
- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install uv
Expand All @@ -53,15 +53,15 @@ jobs:
- name: flake8 typeshed using PR branch
run: |
cd new_plugin
uv pip install -e . --system
uv pip install -e . --system --reinstall
cd ../typeshed
flake8 --exit-zero --color never --output-file ../new_errors.txt
- name: Get diff between the two runs
run: |
echo ${{ github.event.pull_request.number }} | tee pr_number.txt
diff old_errors.txt new_errors.txt | tee errors_diff.txt
- name: Upload diff and PR number
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: typeshed_primer_errors
path: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/typeshed_primer_comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Download errors
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
script: await require('.github/scripts/typeshed_primer_download_errors.js')({github, context})
- run: unzip errors.zip
- name: Post comment
id: post-comment
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: return await require('.github/scripts/typeshed_primer_post_comment.js')({github, context})
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0 # must match pyproject.toml
rev: v4.6.0 # must match pyproject.toml
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -9,7 +9,7 @@ repos:
- id: check-merge-conflict
- id: mixed-line-ending
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.3.0 # must match pyproject.toml
rev: 24.4.2 # must match pyproject.toml
hooks:
- id: black
language_version: python3.8
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Bugfixes
* Allow the use of `typing_extensions.TypeVar` in stubs.
`typing_extensions.TypeVar` has the *default* parameter,
which only exists on Python 3.13+ when using `typing.TypeVar`.
* Reduce false positives from Y052 in relation to enum subclasses.

Other changes
* Declare support for Python 3.13
Expand Down
132 changes: 66 additions & 66 deletions ERRORCODES.md

Large diffs are not rendered by default.

19 changes: 8 additions & 11 deletions pyi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from functools import cached_property, partial
from itertools import chain, groupby, zip_longest
from keyword import iskeyword
from typing import TYPE_CHECKING, Any, ClassVar, NamedTuple, Union
from typing import TYPE_CHECKING, Any, ClassVar, NamedTuple, Protocol, Union

from flake8 import checker
from flake8.options.manager import OptionManager
Expand Down Expand Up @@ -62,6 +62,11 @@ class TypeVarInfo(NamedTuple):
name: str


class NodeWithLocation(Protocol):
lineno: int
col_offset: int


def all_equal(iterable: Iterable[object]) -> bool:
"""Returns True if all the elements are equal to each other.
Expand Down Expand Up @@ -696,11 +701,6 @@ def _analyse_typing_Literal(node: ast.Subscript) -> TypingLiteralAnalysis:
)


_KNOWN_ENUM_BASES = frozenset(
{"Enum", "Flag", "IntEnum", "IntFlag", "StrEnum", "ReprEnum"}
)


_COMMON_METACLASSES = {
"type": "builtins",
"ABCMeta": "abc",
Expand Down Expand Up @@ -734,10 +734,7 @@ def is_typeddict_class(self) -> bool:

@cached_property
def is_enum_class(self) -> bool:
return any(
self.contains_in_bases(enum_cls, from_={"enum"})
for enum_cls in _KNOWN_ENUM_BASES
)
return any(base_name.endswith(("Enum", "Flag")) for base_name in self.bases_map)

@cached_property
def is_metaclass(self) -> bool:
Expand Down Expand Up @@ -2245,7 +2242,7 @@ def check_arg_default(self, arg: ast.arg, default: ast.expr | None) -> None:
if default is not None and not _is_valid_default_value_with_annotation(default):
self.error(default, (Y014 if arg.annotation is None else Y011))

def error(self, node: ast.AST, message: str) -> None:
def error(self, node: NodeWithLocation, message: str) -> None:
self.errors.append(Error(node.lineno, node.col_offset, message, PyiTreeChecker))

def _check_for_unused_things(self) -> None:
Expand Down
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ dependencies = [

[project.optional-dependencies]
dev = [
"black==24.3.0", # Must match .pre-commit-config.yaml
"flake8-bugbear==24.2.6",
"black==24.4.2", # Must match .pre-commit-config.yaml
"flake8-bugbear==24.4.26",
"flake8-noqa==1.4.0",
"isort==5.13.2", # Must match .pre-commit-config.yaml
"mypy==1.9.0",
"pre-commit-hooks==4.5.0", # Must match .pre-commit-config.yaml
"pytest==8.1.1",
"pytest-xdist==3.5.0",
"mypy==1.10.0",
"pre-commit-hooks==4.6.0", # Must match .pre-commit-config.yaml
"pytest==8.2.2",
"pytest-xdist==3.6.1",
"types-pyflakes<4",
]

Expand Down
5 changes: 5 additions & 0 deletions tests/attribute_annotations.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,8 @@ class Enum6(ReprEnum):

class Enum7(enum.Enum):
FOO = "foo"

class SpecialEnum(enum.Enum): ...

class SubclassOfSpecialEnum(SpecialEnum):
STILL_OKAY = "foo"

0 comments on commit 8122d4f

Please sign in to comment.