Skip to content

False positive bad-argument-type when calling a method with AnyStr #2644

Closed

Description

@superbobry

Describe the Bug

Reproducer:

from typing import AnyStr

class A:
  @classmethod
  def create(cls, x: AnyStr | None): ...


def test(x: AnyStr | None):
  A.create(x)

Output:

ERROR Argument `AnyStr | None` is not assignable to parameter `x` with type `str | None` in function `A.create` [bad-argument-type]
  --> /tmp/foo.py:10:12
   |
10 |   A.create(x)

It looks like AnyStr is specialized to str? Possibly a duplicate of #2370.

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

Activity

  1. added theissue type on Mar 5, 2026
  2. added this to the V1 Release milestone on Mar 16, 2026
  3. self-assigned this
    on Mar 17, 2026
  4. migeed-z commented on Mar 19, 2026

    @migeed-z
    Contributor

    This appears to be related to #105? it looks like we are pinning the typevar that has type AnyStr to str. So to fundamentally solve this, I think issue 105 would have to be solved first. So this is blocked by the pinning issue. cc @rchen152 in case there is an alternative thought.

  5. rchen152 commented on Mar 20, 2026

    @rchen152
    Contributor

    @migeed-z Might worth checking what type we're passing in to create in the A.create(x) call - it's possible that we're not handling AnyStr correctly there. But if we are, then yeah, the str | None in the error message suggests that we're probably pinning AnyStr to the wrong type.

  6. github-actions commented on Apr 10, 2026

    @github-actions

    This issue has someone assigned, but has not had recent activity for more than 2 weeks.

    If you are still working on this issue, please add a comment so everyone knows. Otherwise, please unassign yourself and allow someone else to take over.

    Thank you for your contributions!

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

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions