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

AssertionError: Must not defer during final iteration #12113

Closed
mostrows2 opened this issue Feb 2, 2022 · 3 comments
Closed

AssertionError: Must not defer during final iteration #12113

mostrows2 opened this issue Feb 2, 2022 · 3 comments

Comments

@mostrows2
Copy link

Crash Report

Running myyp produces: AssertionError: Must not defer during final iteration

Traceback

> mypy . --show-traceback
./mypybug.py:18: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.940+dev.c0e49abcf27ff59e761f3ec06a24ee94e700464d
Traceback (most recent call last):
  File "/Users/mostrows/.pyenv/versions/3.10.1/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/Users/mostrows/.pyenv/versions/3.10.1/lib/python3.10/site-packages/mypy/__main__.py", line 12, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "/Users/mostrows/.pyenv/versions/3.10.1/lib/python3.10/site-packages/mypy/main.py", line 96, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/Users/mostrows/.pyenv/versions/3.10.1/lib/python3.10/site-packages/mypy/main.py", line 173, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/Users/mostrows/.pyenv/versions/3.10.1/lib/python3.10/site-packages/mypy/build.py", line 180, in build
    result = _build(
  File "/Users/mostrows/.pyenv/versions/3.10.1/lib/python3.10/site-packages/mypy/build.py", line 256, in _build
    graph = dispatch(sources, manager, stdout)
  File "/Users/mostrows/.pyenv/versions/3.10.1/lib/python3.10/site-packages/mypy/build.py", line 2715, in dispatch
    process_graph(graph, manager)
  File "/Users/mostrows/.pyenv/versions/3.10.1/lib/python3.10/site-packages/mypy/build.py", line 3046, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/Users/mostrows/.pyenv/versions/3.10.1/lib/python3.10/site-packages/mypy/build.py", line 3138, in process_stale_scc
    mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)
  File "/Users/mostrows/.pyenv/versions/3.10.1/lib/python3.10/site-packages/mypy/semanal_main.py", line 79, in semantic_analysis_for_scc
    process_functions(graph, scc, patches)
  File "/Users/mostrows/.pyenv/versions/3.10.1/lib/python3.10/site-packages/mypy/semanal_main.py", line 233, in process_functions
    process_top_level_function(analyzer,
  File "/Users/mostrows/.pyenv/versions/3.10.1/lib/python3.10/site-packages/mypy/semanal_main.py", line 274, in process_top_level_function
    deferred, incomplete, progress = semantic_analyze_target(target, state, node, active_type,
  File "/Users/mostrows/.pyenv/versions/3.10.1/lib/python3.10/site-packages/mypy/semanal_main.py", line 326, in semantic_analyze_target
    analyzer.refresh_partial(refresh_node,
  File "/Users/mostrows/.pyenv/versions/3.10.1/lib/python3.10/site-packages/mypy/semanal.py", line 415, in refresh_partial
    self.accept(node)
  File "/Users/mostrows/.pyenv/versions/3.10.1/lib/python3.10/site-packages/mypy/semanal.py", line 5171, in accept
    node.accept(self)
  File "/Users/mostrows/.pyenv/versions/3.10.1/lib/python3.10/site-packages/mypy/nodes.py", line 730, in accept
    return visitor.visit_func_def(self)
  File "/Users/mostrows/.pyenv/versions/3.10.1/lib/python3.10/site-packages/mypy/semanal.py", line 628, in visit_func_def
    self.analyze_func_def(defn)
  File "/Users/mostrows/.pyenv/versions/3.10.1/lib/python3.10/site-packages/mypy/semanal.py", line 660, in analyze_func_def
    self.defer(defn)
  File "/Users/mostrows/.pyenv/versions/3.10.1/lib/python3.10/site-packages/mypy/semanal.py", line 4871, in defer
    assert not self.final_iteration, 'Must not defer during final iteration'
AssertionError: Must not defer during final iteration
./mypybug.py:18: : note: use --pdb to drop into pdb

To Reproduce

source of mypybug.py:

import dataclasses
import typing

if typing.TYPE_CHECKING:
    import classb as b
    
ItemType = typing.TypeVar('ItemType', bound='b.ClassB')

class Item(typing.Protocol):
    name: str

class ItemBase(typing.Generic[ItemType]):
    pass

# dataclasses required to trigger bug.
@dataclasses.dataclass(kw_only=True)
class ItemBaseX(ItemBase[ItemType]):
    name: str

Source of classb.py:

import typing

# This import is required to trigger bug.
import mypybug as eitem

class ClassB(typing.Protocol):
    field: str

Executed:

mypy mypybug.py

Your Environment

  • Mypy version used: 0.940+dev.c0e49abcf27ff59e761f3ec06a24ee94e700464d (and others)
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.10.1
  • Operating system and version: mac os 12.1
@mostrows2 mostrows2 added the crash label Feb 2, 2022
@felixmeziere
Copy link

Same issue here!

@AlexWaygood
Copy link
Member

AlexWaygood commented Mar 24, 2022

Same assertion is hit in #12252, #11728, #12112, #10672 and #10140

@JukkaL
Copy link
Collaborator

JukkaL commented May 11, 2022

This was fixed in #12762.

@JukkaL JukkaL closed this as completed May 11, 2022
provinzkraut added a commit to litestar-org/litestar that referenced this issue Oct 27, 2022
* Initial draft for server-side sessions and unified session-middleware interface

* Implement SessionMiddleware with backends, basic server-session backends. Integrate backends with existing tests

* Initial draft for server-side sessions and unified session-middleware interface

* Implement SessionMiddleware with backends, basic server-session backends. Integrate backends with existing tests

* Initial draft for server-side sessions and unified session-middleware interface

* Implement SessionMiddleware with backends, basic server-session backends. Integrate backends with existing tests

* v1.30.0

* docs: add mookrs as a contributor for doc (#637)

* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>

* Minor code cleanup

* Improve SQLAlchemy backend, support sync/async

* Improved backwards compatibility, typing and tests

* Simplify session backend configuration

* Add expiry mechanism to FakeAsyncMemcached, improve typing

* Test all session backends

* Remove a merge artifact

* Remove identity-source support for now

* Add docstrings to session backends, improve typing

* Minor styling fixes

* Add reference docs for session middleware

* Fix type annotations

* Initial draft for server-side sessions and unified session-middleware interface

* Implement SessionMiddleware with backends, basic server-session backends. Integrate backends with existing tests

* Initial draft for server-side sessions and unified session-middleware interface

* Implement SessionMiddleware with backends, basic server-session backends. Integrate backends with existing tests

* Initial draft for server-side sessions and unified session-middleware interface

* Implement SessionMiddleware with backends, basic server-session backends. Integrate backends with existing tests

* v1.30.0

* docs: add mookrs as a contributor for doc (#637)

* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>

* Minor code cleanup

* Improved backwards compatibility, typing and tests

* Test all session backends

* Remove a merge artifact

* session docs draft

* Disable MD052 in markdownlint

MD052 messes with mkdocs material's code highlighting

* Add aiomcache and redis types to pylint dependencies

* Remove `backend` property from BaseBackendConfig.

This proved difficult to type correctly, and I was hitting python/mypy#12113 (or some variety), so I removed it for now

* Add / update reference and usage documentation + some docstrings for session middleware

* Remove unused imports

* Move session backend config to the top

* Some minor documentation adjustments

* Improve docstrings

Add missing args and returns, add missing docstrings

* Rename SessionBackend > BaseSessionBackend

* Add _sync suffix to private synchronous methods

* Move all type variables to top of the file

* Use explicit "import from" consistently

* Make FileStorageMetadataWrapper a NamedTuple

* Add `make_filename` option to FileBackendConfig

* Move fake_memcached.FakeAsyncMemcached to tests/mocks.py

* Implement MemoryBackend using SimpleCacheBackend

* Add __slots__ for session middleware

* Add support for all session backends to TestClient

* Update starlite/middleware/session/sqlalchemy_backend.py

Co-authored-by: Na'aman Hirschfeld <nhirschfeld@gmail.com>

* Update starlite/testing/test_client/client.py

Co-authored-by: Na'aman Hirschfeld <nhirschfeld@gmail.com>

* Update starlite/middleware/session/sqlalchemy_backend.py

Co-authored-by: Na'aman Hirschfeld <nhirschfeld@gmail.com>

* Update starlite/middleware/session/memcached_backend.py

Co-authored-by: Na'aman Hirschfeld <nhirschfeld@gmail.com>

* Update starlite/middleware/session/sqlalchemy_backend.py

Co-authored-by: Na'aman Hirschfeld <nhirschfeld@gmail.com>

* Update starlite/middleware/session/cookie_backend.py

Co-authored-by: Na'aman Hirschfeld <nhirschfeld@gmail.com>

* Update starlite/middleware/session/base.py

Co-authored-by: Na'aman Hirschfeld <nhirschfeld@gmail.com>

* Update starlite/testing/test_client/client.py

Co-authored-by: Na'aman Hirschfeld <nhirschfeld@gmail.com>

* Update starlite/testing/test_client/client.py

Co-authored-by: Na'aman Hirschfeld <nhirschfeld@gmail.com>

* Implement support for session backends in TestClient

* Make sqlalchemy session examples "run as-is"

* Fix lower-casing of header values. (#693)

A bug was introduced as part of #626, that would lower case header values

* Remove types-redis

* Add middleware bypassing to SessionMiddleware

Co-authored-by: Peter Schutt <peter.github@proton.me>
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Co-authored-by: Na'aman Hirschfeld <nhirschfeld@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants