Mypy: New semantic analyzer: possible cyclic definition for ignored recursive type

Created on 26 Jun 2019  路  5Comments  路  Source: python/mypy

We are using a type definition that looks like this for returning dicts that should be JSON serializable:

Serializable = Dict[  # type: ignore
    str, Union[
        'Serializable', List['Serializable'], Tuple['Serializable'], float, str,
        datetime.datetime, datetime.time]]

Without the new semantic analyzer this passes and gives errors for dicts with incorrectly typed values one level down.

However with the new semantic analyzer this breaks on both the definition of the type:

error: Cannot resolve name "Serializable" (possible cyclic definition)

And on imports of the type in other modules:

error: Module '...serialize' has no attribute 'Serializable'

This is when using stable mypy from PyPI (mypy 0.711) with mypy --new-semantic-analyzer . and the following settings:

[mypy]
ignore_missing_imports = True
strict_optional = True
no_implicit_optional = True
check_untyped_defs = True
disallow_incomplete_defs = True
plugins = sqlmypy

I am aware that recursive types are not yet supported, but I still thought it was worth reporting this as it's a feature regression.

Most helpful comment

This is a known limitation.

Known to whom?

Can the mypy FAQ document this?

All 5 comments

This is a known limitation. In the process of migrating to new analyzer we dropped some partial support of recursive types. It will be brought back in near future (in the form of general recursive types support).

Can't wait! We like to use this for our serializable structures as well.

This is a known limitation.

Known to whom?

Can the mypy FAQ document this?

Is there a tracker so that people can find out when this will be resolved? Having the ticket closed suggests that there's no additional work to be done?

@ikelos There is already an issue for recursive types that isn't very hard to find: https://github.com/python/mypy/issues/731

Was this page helpful?
0 / 5 - 0 ratings