Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stubtest: False-positives with parameter name mangling outside of classes #14560

Closed
Avasam opened this issue Jan 30, 2023 · 0 comments · Fixed by #18756
Closed

stubtest: False-positives with parameter name mangling outside of classes #14560

Avasam opened this issue Jan 30, 2023 · 0 comments · Fixed by #18756
Labels
bug mypy got something wrong topic-stubtest

Comments

@Avasam
Copy link
Contributor

Avasam commented Jan 30, 2023

Bug Report

It seems that when the implementation defines a function (not inside a class) with a parameter that has double leading underscore, it can become impossible to type for stubtest. See the following example in SQLAlchemy: python/typeshed#9596 (comment)

(A clear and concise description of what the bug is.)

To Reproduce

In typeshed: python .\tests\stubtest_third_party.py sqlalchemy

with the following stub definitions:

# sqlalchemy.testing.util
def resolve_lambda(__fn, **kw): ...

# sqlalchemy.orm.collections
class MappedCollection(dict[_KT, _VT]):
    # [...]
    # This function is actually defined dynamically outside the class
    @overload
    def update(self, __other: SupportsKeysAndGetItem[_KT, _VT], **kwargs: _VT) -> None: ...
    @overload
    def update(self, __other: Iterable[tuple[_KT, _VT]], **kwargs: _VT) -> None: ...
    @overload
    def update(self, __other: symbol | _symbol = ..., **kwargs: _VT) -> None: ...

Expected Behavior

No errors

Actual Behavior

error: sqlalchemy.orm.collections.MappedCollection.update is inconsistent, stub argument "__other" differs from runtime argument "__other"
Stub: at line 127 in file E:\Users\Avasam\Documents\Git\typeshed\stubs\sqlalchemy\sqlalchemy\orm\collections.pyi
Overload(def (self: sqlalchemy.orm.collections.MappedCollection[_KT`1, _VT`2], _typeshed.SupportsKeysAndGetItem[_KT`1, _VT`2], **kwargs: _VT`2), def (self: sqlalchemy.orm.collections.MappedCollection[_KT`1, _VT`2], typing.Iterable[Tuple[_KT`1, _VT`2]], **kwargs: _VT`2), def (self: sqlalchemy.orm.collections.MappedCollection[_KT`1, _VT`2], Union[sqlalchemy.util.langhelpers.symbol, sqlalchemy.util.langhelpers._symbol] =, **kwargs: _VT`2))
Inferred signature: def (self: sqlalchemy.orm.collections.MappedCollection[_KT`1, _VT`2], __other: Union[_typeshed.SupportsKeysAndGetItem[_KT`1, _VT`2], typing.Iterable[Tuple[_KT`1, _VT`2]], sqlalchemy.util.langhelpers.symbol, sqlalchemy.util.langhelpers._symbol] = ..., **kwargs)
Runtime: at line 1402 in file C:\Users\Avasam\AppData\Local\Temp\tmpfa40k4ao\lib\site-packages\sqlalchemy\orm\collections.py
def (self, __other=symbol('Unspecified'), **kw)

error: sqlalchemy.orm.collections.MappedCollection.update is inconsistent, stub argument "__other" should be positional or keyword (remove leading double underscore)
Stub: at line 127 in file E:\Users\Avasam\Documents\Git\typeshed\stubs\sqlalchemy\sqlalchemy\orm\collections.pyi
Overload(def (self: sqlalchemy.orm.collections.MappedCollection[_KT`1, _VT`2], _typeshed.SupportsKeysAndGetItem[_KT`1, _VT`2], **kwargs: _VT`2), def (self: sqlalchemy.orm.collections.MappedCollection[_KT`1, _VT`2], typing.Iterable[Tuple[_KT`1, _VT`2]], **kwargs: _VT`2), def (self: sqlalchemy.orm.collections.MappedCollection[_KT`1, _VT`2], Union[sqlalchemy.util.langhelpers.symbol, sqlalchemy.util.langhelpers._symbol] =, **kwargs: _VT`2))
Inferred signature: def (self: sqlalchemy.orm.collections.MappedCollection[_KT`1, _VT`2], __other: Union[_typeshed.SupportsKeysAndGetItem[_KT`1, _VT`2], typing.Iterable[Tuple[_KT`1, _VT`2]], sqlalchemy.util.langhelpers.symbol, sqlalchemy.util.langhelpers._symbol] = ..., **kwargs)
Runtime: at line 1402 in file C:\Users\Avasam\AppData\Local\Temp\tmpfa40k4ao\lib\site-packages\sqlalchemy\orm\collections.py
def (self, __other=symbol('Unspecified'), **kw)

error: sqlalchemy.testing.resolve_lambda is inconsistent, stub argument "__fn" differs from runtime argument "__fn"
Stub: at line 28 in file E:\Users\Avasam\Documents\Git\typeshed\stubs\sqlalchemy\sqlalchemy\testing\__init__.pyi
None
Runtime: at line 322 in file C:\Users\Avasam\AppData\Local\Temp\tmpfa40k4ao\lib\site-packages\sqlalchemy\testing\util.py
def (__fn, **kw)

error: sqlalchemy.testing.resolve_lambda is inconsistent, stub argument "__fn" should be positional or keyword (remove leading double underscore)
Stub: at line 28 in file E:\Users\Avasam\Documents\Git\typeshed\stubs\sqlalchemy\sqlalchemy\testing\__init__.pyi
None
Runtime: at line 322 in file C:\Users\Avasam\AppData\Local\Temp\tmpfa40k4ao\lib\site-packages\sqlalchemy\testing\util.py
def (__fn, **kw)

error: sqlalchemy.testing.util.resolve_lambda is inconsistent, stub argument "__fn" differs from 
runtime argument "__fn"
Stub: at line 28 in file E:\Users\Avasam\Documents\Git\typeshed\stubs\sqlalchemy\sqlalchemy\testing\util.pyi
None
Runtime: at line 322 in file C:\Users\Avasam\AppData\Local\Temp\tmpfa40k4ao\lib\site-packages\sqlalchemy\testing\util.py
def (__fn, **kw)

error: sqlalchemy.testing.util.resolve_lambda is inconsistent, stub argument "__fn" should be positional or keyword (remove leading double underscore)
Stub: at line 28 in file E:\Users\Avasam\Documents\Git\typeshed\stubs\sqlalchemy\sqlalchemy\testing\util.pyi
None
Runtime: at line 322 in file C:\Users\Avasam\AppData\Local\Temp\tmpfa40k4ao\lib\site-packages\sqlalchemy\testing\util.py
def (__fn, **kw)

Found 6 errors (checked 228 modules)

Your Environment

  • Mypy version used: mypy 0.991 (compiled: yes)
  • Mypy command-line flags: (from typeshed, see above)
  • Mypy configuration options from mypy.ini (and other config files): (from typeshed, see above)
  • Python version used: Python 3.9.13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-stubtest
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants