Skip to content

should allow assignable gradual type in super() #987

@CharlesPerrotMinot

Description

@CharlesPerrotMinot

Summary

ty errors saying the annotation of the cls as type[Any] for a class inheriting from type, in the init, is wrong.

We're getting

error[invalid-super-argument]: `type[Any]` is not an instance or subclass of `<class 'BuilderMeta'>` in `super(<class 'BuilderMeta'>, type[Any])` call
    |
453 |         dct["use_legacy"] = define_builder_use_legacy()
454 |         dct["dict"] = define_builder_dict()
455 |         instance = super().__new__(cls, name, bases, dct)
    |                    ^^^^^^^
456 |         instance.__field_names__ = field_names
457 |         instance.from_behave_context = define_builder_from_behave_context(instance)
    |
info: rule `invalid-super-argument` is enabled by default

Which points to the following code

class BuilderMeta(type):
    def __new__(
        cls: type[Any],
        name: str,
        bases: tuple[type, ...],
        dct: dict[str, Any],
    ) -> "BuilderMeta":
        instance = super().__new__(cls, name, bases, dct)

Works without issues with mypy 1.17.1, with this config:

allow_subclassing_any=true
allow_untyped_decorators=true
ignore_missing_imports = true
no_warn_return_any=true
strict=true

Version

0.0.1-alpha.18

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtyping semanticstyping-module features, spec compliance, etc

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions