KotlinIsland / basedmypy

Based Python static type checker with baseline, sane default settings and based typing features
https://kotlinisland.github.io/basedmypy/
Other
146 stars 4 forks source link

Internal error with nested `Unpack` and `@overload` #747

Open jorenham opened 3 months ago

jorenham commented 3 months ago

Describe the problem, ie expected/actual result (if it's not blatantly obvious)

The relevant code:

https://github.com/jorenham/scipy-stubs/blob/master/scipy-stubs/stats/_distn_infrastructure.pyi#L197-L233

When I run mypy --show-traceback scipy-stubs/stats/_distn_infrastructure.pyi:

scipy-stubs/stats/_distn_infrastructure.pyi:197: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://kotlinisland.github.io/basedmypy/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/KotlinIsland/basedmypy/issues
version: 2.7.0+dev.4c2c2e5000d53f89d59fa0b208be793b71e9c2fe
Traceback (most recent call last):
  File "/dev/scipy-stubs/.venv/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/main.py", line 108, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/main.py", line 217, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/build.py", line 198, in build
    result = _build(
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/build.py", line 276, in _build
    graph = dispatch(sources, manager, stdout)
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/build.py", line 3092, in dispatch
    process_graph(graph, manager)
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/build.py", line 3492, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/build.py", line 3593, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/build.py", line 2455, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/checker.py", line 505, in check_first_pass
    self.accept(d)
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/checker.py", line 613, in accept
    stmt.accept(self)
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/nodes.py", line 1187, in accept
    return visitor.visit_class_def(self)
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/checker.py", line 2650, in visit_class_def
    self.accept(defn.defs)
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/checker.py", line 613, in accept
    stmt.accept(self)
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/nodes.py", line 1268, in accept
    return visitor.visit_block(self)
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/checker.py", line 3116, in visit_block
    self.accept(s)
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/checker.py", line 613, in accept
    stmt.accept(self)
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/nodes.py", line 591, in accept
    return visitor.visit_overloaded_func_def(self)
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/checker.py", line 650, in visit_overloaded_func_def
    self._visit_overloaded_func_def(defn, do_items)
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/checker.py", line 681, in _visit_overloaded_func_def
    self.check_overlapping_overloads(defn)
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/checker.py", line 814, in check_overlapping_overloads
    if is_unsafe_overlapping_overload_signatures(sig1, sig2, type_vars):
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/checker.py", line 8549, in is_unsafe_overlapping_overload_signatures
    is_callable_compatible(
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/subtypes.py", line 1623, in is_callable_compatible
    return are_parameters_compatible(
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/subtypes.py", line 1730, in are_parameters_compatible
    if _incompatible(left_star, right_star) or _incompatible(left_star2, right_star2):
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/subtypes.py", line 1728, in _incompatible
    return not is_compat(right_arg.typ, left_arg.typ)
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/checker.py", line 9083, in is_overlapping_types_for_overload
    return is_overlapping_types(
  File "/dev/scipy-stubs/.venv/lib/python3.10/site-packages/mypy/meet.py", line 619, in is_overlapping_types
    assert type(left) != type(right), f"{type(left)} vs {type(right)}"
AssertionError: <class 'mypy.types.UnpackType'> vs <class 'mypy.types.UnpackType'>
scipy-stubs/stats/_distn_infrastructure.pyi:197: : note: use --pdb to drop into pdb

so here I am 🤷🏻


(yes, I'm actually stubbing scipy 🙃)

Gist to reproduce

https://github.com/jorenham/scipy-stubs/blob/master/scipy-stubs/stats/_distn_infrastructure.pyi#L197-L233

Basedmypy version

basedmypy 2.7.0+dev.4c2c2e5000d53f89d59fa0b208be793b71e9c2fe (compiled: no)
Based on mypy 1.11.0+dev

Command-line flags

No response

Configuration options from pyproject.toml (and other config files)

disable_bytearray_promotion=true; disable_memoryview_promotion=true; disallow_any_explicit=false; warn_unuseda_ignores=true

Python version used

three dot ten dot twelve

Operating system and version

PopOS! / Ubuntu 22.04 (won't recommend)

KotlinIsland commented 2 months ago

looks like it's also affecting upstream, here's a minified example:

from typing import overload

from typing_extensions import Unpack

class A:
    @overload
    def f(self, *args: Unpack[tuple[Unpack[tuple[str, ...]]]]) -> int: ...
    @overload
    def f(self): ...

playground

KotlinIsland commented 2 months ago

btw, i would recomment uv (+ pyprojectx) over poetry

i think it would be a good idea to add this project to the [based]mypy primer

additionally, i would like to keep an open dialogue with you about any changes that would be introduced into basedmypy since you are using it, do you have discord or something?

jorenham commented 2 months ago

@KotlinIsland sure, is telegram ok?

jorenham commented 2 months ago

@KotlinIsland the most nerdy anti-scraper measure I could think of:

f"+{0x75e67144a}"
KotlinIsland commented 2 months ago

my telegram is: @KotlinIslandsTaken