Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/mypy_primer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
- 'mypy/stubgen.py'
- 'mypy/stubgenc.py'
- 'mypy/test/**'
- 'scripts/**'
- 'test-data/**'

jobs:
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ repos:
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 5.0.4 # must match test-requirements.txt
rev: 3.9.2 # must match test-requirements.txt
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear==22.8.23 # must match test-requirements.txt
- flake8-noqa==1.2.9 # must match test-requirements.txt
- flake8-bugbear==22.7.1 # must match test-requirements.txt
- flake8-noqa==1.2.8 # must match test-requirements.txt
8 changes: 1 addition & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,10 @@ python3 runtests.py
You can also use `tox` to run tests (`tox` handles setting up the test environment for you):
```
tox -e py

# Or some specific python version:
tox -e py39

# Or some specific command:
tox -e lint
```

Some useful commands for running specific tests include:
```bash
```
# Use mypy to check mypy's own code
python3 runtests.py self
# or equivalently:
Expand Down
2 changes: 1 addition & 1 deletion build-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-r mypy-requirements.txt
types-psutil
types-setuptools
types-typed-ast>=1.5.8,<1.6.0
types-typed-ast>=1.5.0,<1.6.0
8 changes: 4 additions & 4 deletions misc/async_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def plain_host_generator(func) -> Generator[str, None, None]:
x = 0
f = func()
try:
x = yield from f # noqa: F841
x = yield from f
finally:
try:
f.close()
Expand All @@ -80,7 +80,7 @@ def plain_host_generator(func) -> Generator[str, None, None]:

async def plain_host_coroutine(func) -> None:
x = 0
x = await func() # noqa: F841
x = await func()


@coroutine
Expand All @@ -89,7 +89,7 @@ def decorated_host_generator(func) -> Generator[str, None, None]:
x = 0
f = func()
try:
x = yield from f # noqa: F841
x = yield from f
finally:
try:
f.close()
Expand All @@ -100,7 +100,7 @@ def decorated_host_generator(func) -> Generator[str, None, None]:
@coroutine
async def decorated_host_coroutine(func) -> None:
x = 0
x = await func() # noqa: F841
x = await func()


# Main driver.
Expand Down
2 changes: 1 addition & 1 deletion misc/cherry-pick-typeshed.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def main() -> None:
sys.exit(f"error: Invalid commit {commit!r}")

if not os.path.exists("mypy") or not os.path.exists("mypyc"):
sys.exit("error: This script must be run at the mypy repository root directory")
sys.exit(f"error: This script must be run at the mypy repository root directory")

with tempfile.TemporaryDirectory() as d:
diff_file = os.path.join(d, "diff")
Expand Down
2 changes: 1 addition & 1 deletion misc/find_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# " Convert to 0-based column offsets
# let startcol = startcol - 1
# " Change this line to point to the find_type.py script.
# execute '!python3 /path/to/mypy/misc/find_type.py % ' . startline . ' ' . startcol . ' ' . endline . ' ' . endcol . ' ' . mypycmd
# execute '!python3 /path/to/mypy/scripts/find_type.py % ' . startline . ' ' . startcol . ' ' . endline . ' ' . endcol . ' ' . mypycmd
# endfunction
# vnoremap <Leader>t :call RevealType()<CR>
#
Expand Down
12 changes: 6 additions & 6 deletions misc/fix_annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ def transform(self, node, results):
#
# "Compact" functions (e.g. "def foo(x, y): return max(x, y)")
# have a different structure that isn't matched by PATTERN.
#
# print('-'*60)
# print(node)
# for i, ch in enumerate(children):
# print(i, repr(ch.prefix), repr(ch))
#

## print('-'*60)
## print(node)
## for i, ch in enumerate(children):
## print(i, repr(ch.prefix), repr(ch))

# Check if there's already an annotation.
for ch in children:
if ch.prefix.lstrip().startswith("# type:"):
Expand Down
11 changes: 5 additions & 6 deletions misc/proper_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from typing import Callable

from mypy.checker import TypeChecker
from mypy.nodes import TypeInfo
from mypy.plugin import FunctionContext, Plugin
from mypy.subtypes import is_proper_subtype
Expand Down Expand Up @@ -51,8 +50,10 @@ def isinstance_proper_hook(ctx: FunctionContext) -> Type:
right = get_proper_type(ctx.arg_types[1][0])
for arg in ctx.arg_types[0]:
if (
is_improper_type(arg) or isinstance(get_proper_type(arg), AnyType)
) and is_dangerous_target(right):
is_improper_type(arg)
or isinstance(get_proper_type(arg), AnyType)
and is_dangerous_target(right)
):
if is_special_target(right):
return ctx.default_return_type
ctx.api.fail(
Expand Down Expand Up @@ -154,9 +155,7 @@ def proper_types_hook(ctx: FunctionContext) -> Type:


def get_proper_type_instance(ctx: FunctionContext) -> Instance:
checker = ctx.api
assert isinstance(checker, TypeChecker)
types = checker.modules["mypy.types"]
types = ctx.api.modules["mypy.types"] # type: ignore
proper_type_info = types.names["ProperType"]
assert isinstance(proper_type_info.node, TypeInfo)
return Instance(proper_type_info.node, [])
Expand Down
2 changes: 1 addition & 1 deletion misc/upload-pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def download_asset(asset: dict[str, Any], dst: Path) -> Path:


def download_all_release_assets(release: dict[str, Any], dst: Path) -> None:
print("Downloading assets...")
print(f"Downloading assets...")
with ThreadPoolExecutor() as e:
for asset in e.map(lambda asset: download_asset(asset, dst), release["assets"]):
print(f"Downloaded {asset}")
Expand Down
10 changes: 3 additions & 7 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1292,15 +1292,11 @@ def find_cache_meta(id: str, path: str, manager: BuildManager) -> CacheMeta | No
)

# Don't check for path match, that is dealt with in validate_meta().
#
# TODO: these `type: ignore`s wouldn't be necessary
# if the type annotations for CacheMeta were more accurate
# (all of these attributes can be `None`)
if (
m.id != id
or m.mtime is None # type: ignore[redundant-expr]
or m.size is None # type: ignore[redundant-expr]
or m.dependencies is None # type: ignore[redundant-expr]
or m.mtime is None
or m.size is None
or m.dependencies is None
or m.data_mtime is None
):
manager.log(f"Metadata abandoned for {id}: attributes are missing")
Expand Down
Loading