Skip to content

AnyStr.startswith(AnyStr) fails due to bytes not matching Buffer protocol #5452

Closed

Description

@linuxdaemon

Describe the Bug

from typing import *

def func(a: AnyStr, b: AnyStr) -> bool:
    return a.startswith(b)

Python: 3.12

When creating a function as above, pyrefly fails to resolve the .startswith() call, claiming bytes doesn't satisfy Buffer.

This should resolve correctly, as AnyStr is bound to the same type for a and b, and str.startswith accepts strings and bytes.startswith accepts bytes

Sandbox Link

https://pyrefly.org/sandbox/?project=v2.I6HI1EJOoBqJVqAyNLgEWG4kwZjg6E4C5mpY2EHTth4wnRWVFJdnlmRoJAHjBjPolBUCIAIKUFcACw1gmKeXAosmYFjqxeQpA0ulVIWMkpKCYit9fZj2_KJ0_dQ8_ZT85GJ9FB36CqBUkliWmAku8FCNU8gHR3Ux0FhK4kwdEmXq-GJMHRRhQBV4IwEA

(Only applicable for extension issues) IDE Information

No response

Activity

  1. rchen152 commented on Nov 5, 2026

    @rchen152
    Contributor

    @shahhamdihassan are you still working on this one?

  2. shahhamdihassan commented on Nov 5, 2026

    @shahhamdihassan
    Contributor

    Yes, still on it! The fix is going up for review today, with you and Steven as reviewers. I'll post here once it lands.

  3. shahhamdihassan commented on Nov 9, 2026

    @shahhamdihassan
    Contributor

    The fix for this has landed, so AnyStr methods like startswith and split now accept an AnyStr argument when the receiver is also AnyStr. It'll be in the next release. Thanks for the clear report!

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

Metadata

Metadata

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions