Skip to content

Overriding class level functions (without self) fails with bad-override #2564

@QEDady

Description

@QEDady

Describe the Bug

Pyrefly errors on the following:

class A:
    def foo() -> int:
        return 42

class B(A):
    def foo() -> int: # bad-override
        return 100

with

ERROR sandbox.py:16:9-12: Class member `B.foo` overrides parent class `A` in an inconsistent manner [[bad-override](https://pyrefly.org/en/docs/error-kinds/#bad-override)]
  `B.foo` has type `() -> int`, which is not assignable to `() -> int`, the type of `A.foo`

The above error go away if we add self (or any other parameter) to both functions. Also, annotating them with @staticmethod makes the error goes away. Maybe, pyrefly is injecting some thing under the hood to make these fail?

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIAxAAQDqMUAxrgLYzUAuunAFuwAqkATjDBRS1AMoYcBADS8IcakuqpqxVAHMYAHXQ0A7nxHVSuAK7VGGaoaEQOMBXB6pTM6rHfo1eCxycpMQQ6FoqvoIcPLjohPqUCdQAEjAeHtaWxLDUYDCoHBYiyrhgispoWHj4iEkAtNQA4jCBIqhQdRwQbEHE7Ix8jADWoeF5MDiow-XUAKpw7CIAbvlQAPocwTAAFACUnNyhcH2MgaF5QiKYvfAzMPh9DmzogYaOPLzsAJIAIgCiuXyhWKvAKdnYcAsxGIuCEgW2MEIWkIagCuGYLGyLWc1C0uE6%2BMwolCjggsQUMRWQgULUYuxmtAcTjUWGoQgskVI0VimSJ1EwEBEp3EETMliE1GwQlwhgWQn0%2BjA0pYvVGKkxsMCACp9IwoKg4MoAIK1XzUc1EspgXC4PbUOoAPgiHFN5rdbpEwN8ABYAEwK9B6g3KABC2yNu1dbstuRtdsdzqj7vNnqKvgAjAAGTMBkByEBkERiUiELgsKAUGiCIsiyqyfCZdCQLRFApkuJJSQwdg8DgcYhwRAAeiHhdE4kIsK0Q5g6CHmHRcCHzCbEBbQjbsSHsYlqCWqGgqGwORXzdbXR5uGIF-QcHi6DI3PQdSpcHb1AAvNRdCAAMyEdN-RAfQ8xAAJoDvMhKzmLooEcCQwA5U52zgAMY2tIQWAKNZ0AsFhsDSbYamdfYEzgDghCTNkWjTXIfwAOTwgjKOoYB8AAXx-ED2PzKYuhWAAxaAYAoOtqhIch2KAA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions