diff --git a/mypy/plugins/default.py b/mypy/plugins/default.py index 3476b930307b..b9ec575dabb5 100644 --- a/mypy/plugins/default.py +++ b/mypy/plugins/default.py @@ -365,8 +365,10 @@ def typed_dict_update_signature_callback(ctx: MethodSigContext) -> CallableType: def int_pow_callback(ctx: MethodContext) -> Type: """Infer a more precise return type for int.__pow__.""" - if (len(ctx.arg_types) == 1 - and len(ctx.arg_types[0]) == 1): + # int.__pow__ has an optional modulo argument, + # so we expect 2 argument positions + if (len(ctx.arg_types) == 2 + and len(ctx.arg_types[0]) == 1 and len(ctx.arg_types[1]) == 0): arg = ctx.args[0][0] if isinstance(arg, IntExpr): exponent = arg.value diff --git a/mypy/test/testcmdline.py b/mypy/test/testcmdline.py index 92129d3a78c8..dbefd2893b57 100644 --- a/mypy/test/testcmdline.py +++ b/mypy/test/testcmdline.py @@ -89,6 +89,8 @@ def test_python_cmdline(testcase: DataDrivenTestCase, step: int) -> None: if obvious_result != result: out.append('== Return code: {}'.format(result)) expected_out = testcase.output if step == 1 else testcase.output2[step] + # Strip "tmp/" out of the test so that # E: works... + expected_out = [s.replace("tmp" + os.sep, "") for s in expected_out] assert_string_arrays_equal(expected_out, out, 'Invalid output ({}, line {}){}'.format( testcase.file, testcase.line, diff --git a/test-data/unit/check-expressions.test b/test-data/unit/check-expressions.test index 7b396918fde5..42efa4048501 100644 --- a/test-data/unit/check-expressions.test +++ b/test-data/unit/check-expressions.test @@ -2311,25 +2311,6 @@ class B: ... [builtins fixtures/dict.pyi] --- Type checker default plugin --- --------------------------- - - -[case testIntPow] -a = 1 -b = a + 2 -reveal_type(a**0) # N: Revealed type is 'builtins.int' -reveal_type(a**1) # N: Revealed type is 'builtins.int' -reveal_type(a**2) # N: Revealed type is 'builtins.int' -reveal_type(a**-0) # N: Revealed type is 'builtins.int' -reveal_type(a**-1) # N: Revealed type is 'builtins.float' -reveal_type(a**(-2)) # N: Revealed type is 'builtins.float' -reveal_type(a**b) # N: Revealed type is 'Any' -reveal_type(a.__pow__(2)) # N: Revealed type is 'builtins.int' -reveal_type(a.__pow__(a)) # N: Revealed type is 'Any' -a.__pow__() # E: Too few arguments for "__pow__" of "int" -[builtins fixtures/ops.pyi] - [case testTypeAnnotationNeededMultipleAssignment] x, y = [], [] # E: Need type annotation for 'x' (hint: "x: List[] = ...") \ # E: Need type annotation for 'y' (hint: "y: List[] = ...") diff --git a/test-data/unit/cmdline.test b/test-data/unit/cmdline.test index b1e9c69ad027..f4e8b684cb15 100644 --- a/test-data/unit/cmdline.test +++ b/test-data/unit/cmdline.test @@ -578,6 +578,25 @@ python_version = 3.4 python_version = 3.6 [out] +-- This should be a dumping ground for tests of plugins that are sensitive to +-- typeshed changes. +[case testTypeshedSensitivePlugins] +# cmd: mypy int_pow.py + +[file int_pow.py] +a = 1 +b = a + 2 +reveal_type(a**0) # N: Revealed type is 'builtins.int' +reveal_type(a**1) # N: Revealed type is 'builtins.int' +reveal_type(a**2) # N: Revealed type is 'builtins.int' +reveal_type(a**-0) # N: Revealed type is 'builtins.int' +reveal_type(a**-1) # N: Revealed type is 'builtins.float' +reveal_type(a**(-2)) # N: Revealed type is 'builtins.float' +reveal_type(a**b) # N: Revealed type is 'Any' +reveal_type(a.__pow__(2)) # N: Revealed type is 'builtins.int' +reveal_type(a.__pow__(a)) # N: Revealed type is 'Any' +a.__pow__() # E: Too few arguments for "__pow__" of "int" + [case testDisallowAnyUnimported] # cmd: mypy main.py [file mypy.ini] diff --git a/test-data/unit/fixtures/ops.pyi b/test-data/unit/fixtures/ops.pyi index 0cb390fbadc1..34cfb176243e 100644 --- a/test-data/unit/fixtures/ops.pyi +++ b/test-data/unit/fixtures/ops.pyi @@ -1,4 +1,4 @@ -from typing import overload, Any, Generic, Sequence, Tuple, TypeVar +from typing import overload, Any, Generic, Sequence, Tuple, TypeVar, Optional Tco = TypeVar('Tco', covariant=True) @@ -46,7 +46,7 @@ class int: def __rtruediv__(self, x: 'int') -> 'int': pass def __mod__(self, x: 'int') -> 'int': pass def __floordiv__(self, x: 'int') -> 'int': pass - def __pow__(self, x: 'int') -> Any: pass + def __pow__(self, x: 'int', __modulo: Optional[int] = ...) -> Any: pass def __pos__(self) -> 'int': pass def __neg__(self) -> 'int': pass def __eq__(self, x: object) -> bool: pass pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy