Skip to content

Consider removing six, past, and future support #13567

Open
@sobolevn

Description

@sobolevn

Since python2 is now no longer supported, I think it might be a good time to remove special casing of these libraries.

Why?

  1. None of them are required for python3+ code
  2. All their features are now (long) supported by python3+
  3. Their support is clearly a hack
  4. Code to support them is quite complex:

    mypy/mypy/semanal.py

    Lines 1971 to 2018 in 840a310

    def update_metaclass(self, defn: ClassDef) -> None:
    """Lookup for special metaclass declarations, and update defn fields accordingly.
    * six.with_metaclass(M, B1, B2, ...)
    * @six.add_metaclass(M)
    * future.utils.with_metaclass(M, B1, B2, ...)
    * past.utils.with_metaclass(M, B1, B2, ...)
    """
    # Look for six.with_metaclass(M, B1, B2, ...)
    with_meta_expr: Expression | None = None
    if len(defn.base_type_exprs) == 1:
    base_expr = defn.base_type_exprs[0]
    if isinstance(base_expr, CallExpr) and isinstance(base_expr.callee, RefExpr):
    base_expr.accept(self)
    if (
    base_expr.callee.fullname
    in {
    "six.with_metaclass",
    "future.utils.with_metaclass",
    "past.utils.with_metaclass",
    }
    and len(base_expr.args) >= 1
    and all(kind == ARG_POS for kind in base_expr.arg_kinds)
    ):
    with_meta_expr = base_expr.args[0]
    defn.base_type_exprs = base_expr.args[1:]
    # Look for @six.add_metaclass(M)
    add_meta_expr: Expression | None = None
    for dec_expr in defn.decorators:
    if isinstance(dec_expr, CallExpr) and isinstance(dec_expr.callee, RefExpr):
    dec_expr.callee.accept(self)
    if (
    dec_expr.callee.fullname == "six.add_metaclass"
    and len(dec_expr.args) == 1
    and dec_expr.arg_kinds[0] == ARG_POS
    ):
    add_meta_expr = dec_expr.args[0]
    break
    metas = {defn.metaclass, with_meta_expr, add_meta_expr} - {None}
    if len(metas) == 0:
    return
    if len(metas) > 1:
    self.fail("Multiple metaclass definitions", defn)
    return
    defn.metaclass = metas.pop()
  5. There are multiple places where six. / etc special cases are used: mypy/stubgen.py, mypy/semanal.py, mypyc/irbuild/for_helpers.py

I don't see much benefit in keeping them.

Related #12237

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions