Skip to content

Conversation

@jackulau
Copy link
Contributor

Summary

Fixes #1970

When the implicit-any error is enabled, bare tuple and Callable annotations now generate errors, matching the existing behavior for list.

Before

def f(
    x: list,      # ERROR: implicit-any
    y: tuple,     # no error
    z: Callable,  # no error 
):
    pass

After

def f(
    x: list,      # ERROR: implicit-any
    y: tuple,     # ERROR: implicit-any
    z: Callable,  # ERROR: implicit-any
):
    pass

Changes

  • Add ImplicitAny error for SpecialForm::Tuple, SpecialForm::Callable, and SpecialForm::Type in canonicalize_all_class_types
  • Add ImplicitAny error for ClassDef(tuple) to handle the builtin tuple
  • Add test case covering the fix

Notes

  • Bare builtin type still doesn't error because it's not defined as generic in typeshed (the type class has no type parameters). However, typing.Type does error correctly.

When the implicit-any error is enabled, bare `tuple` and `Callable`
annotations now generate errors like `list` already does.

- Add error for `SpecialForm::Tuple`, `SpecialForm::Callable`, and
  `SpecialForm::Type` in `canonicalize_all_class_types`
- Add error for `ClassDef(tuple)` to handle builtin tuple
- Add test case covering the fix

Note: bare builtin `type` still doesn't error because it's not defined
as generic in typeshed. `typing.Type` does error correctly.
@meta-cla meta-cla bot added the cla signed label Dec 31, 2025
@github-actions

This comment has been minimized.

Copy link
Contributor

@rchen152 rchen152 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The logic looks good, but it would be nice if we could reduce code duplication a bit.

errors.add(
range,
ErrorInfo::Kind(ErrorKind::ImplicitAny),
vec1![
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to pull out the error message creation from

vec1![
format!(
"Cannot determine the type parameter `{}` for generic class `{}`",
tparam.name(),
cls.name(),
),
"Either specify the type argument explicitly, or specify a default for the type variable.".to_owned(),
],
into a reusable helper method rather than copy-pasting?

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

implicit-any doesn't warn on bare type or tuple

3 participants