Skip to content

"Maximum semantic analysis iteration count reached" with conditional imports #12439

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

Closed
JordanLongstaff opened this issue Mar 24, 2022 · 2 comments
Labels
crash semantic-analyzer Problems that happen during semantic analysis

Comments

@JordanLongstaff
Copy link

JordanLongstaff commented Mar 24, 2022

Bug Report

Some imports in our code only exist if the TYPE_CHECKING flag is on, but for some reason mypy doesn't seem to like that.

To Reproduce

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from . import MediaType

class FileFormatError(Exception):
    pass

class MediaTypeValueError(FileFormatError):
    def __init__(self, value):
        super().__init__(f'{value!r} is not a valid media type.')

class UnsupportedFileFormatError(FileFormatError):
    def __init__(self, media_type: 'MediaType'):
        super().__init__('File is not a supported format.', {'media_type': media_type})

Expected Behaviour

Should be OK.

Actual Behaviour

Deferral trace:
    server.misc.file.format.exceptions:4
    server.misc.file.format.exceptions:-1
    ...
server/views/api/home_share/__init__.py: error: INTERNAL ERROR: maximum semantic analysis iteration count reached
Found 1 error in 1 file (errors prevented further checking)

There are thousands more examples throughout the codebase that seem to just be more instances of the same problem in other places. They've been redacted from the above trace; the only one shown is from the To Reproduce example.

Your Environment

  • Mypy version used: 0.941
  • Mypy command-line flags: mypy -p server
  • Mypy configuration options from mypy.ini (and other config files):
mypy_path = $ENCIRCLE_CHECKOUT/server/stubs
plugins = sqlmypy

check_untyped_defs = True
disallow_any_generics = True
disallow_any_unimported = True
disallow_incomplete_defs = True
disallow_subclassing_any = True
disallow_untyped_calls = True
disallow_untyped_decorators = True
disallow_untyped_defs = True
no_implicit_optional = True
# Disabled until https://github.com/python/mypy/issues/8481 is fixed or if we
# can rid of all `import *` in our codebase
no_implicit_reexport = False
strict_equality = True
warn_redundant_casts = True
warn_return_any = True
warn_unused_ignores = True
  • Python version used: 3.9.9
  • Operating system and version: macOS Monterey 12.3
@JordanLongstaff JordanLongstaff added the bug mypy got something wrong label Mar 24, 2022
@AlexWaygood AlexWaygood added crash and removed bug mypy got something wrong labels Mar 24, 2022
@hauntsaninja
Copy link
Collaborator

Do you have a shareable or self-contained repro?

(also fwiw #8481 is fixed :-) )

@AlexWaygood AlexWaygood added the semantic-analyzer Problems that happen during semantic analysis label Mar 26, 2022
@hauntsaninja
Copy link
Collaborator

Closing since there isn't a repro

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Jul 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash semantic-analyzer Problems that happen during semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants