Skip to content

False positive bad-override when subclassing built-in str and adding optional parameter #2309

@lolpack

Description

@lolpack

Describe the Bug

Pyrefly reports bad-override when subclassing str and overriding upper with an additional optional argument. Pyright accepts this code.

class MyString(str):
    def upper(self, locale: str = "en") -> str:
        return super().upper()

This seems like another override compatibility false positive in method signature checking for built-in subclasses.

Sandbox Link (Pyrefly)

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXAAlHAhgOwCYCMD2AHgHQAOAnksiAMZTpxzICy5AygC4BOEmA5gAo43AJSIAOpmTTk2GGGQBXUqRhchMKGAA0yKPhrpYKYV2QBeZOJAxM1kcgC0APmSmJUmV64wOirlJwymoCIsTKquoiIAC%2BuiDoNBwQAG4wAGLQMFQgGDgEJBSxQA

Reference (Pyright)

https://pyright-play.net/?code=MYGwhgzhAECyCeBlALgJwJYDsDmAKCaAlAFwBQ0F0AJgKYBm0ArgA7M2r40h0A00IAe2BgQNYtAKpoAXmgAiGpjmFoAWgB8EtGUq7oqGskapMElu1yEAdCzYdCQA

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions