Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible definition of methods reported when using multiple inheritance #9319

Closed
frerich opened this issue Aug 17, 2020 · 3 comments · Fixed by #18415
Closed

Incompatible definition of methods reported when using multiple inheritance #9319

frerich opened this issue Aug 17, 2020 · 3 comments · Fixed by #18415
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code

Comments

@frerich
Copy link

frerich commented Aug 17, 2020

Using mypy 0.782, errors about incompatible method redefinitions are issued -- but only if multiple inheritance is in play.

How to Reproduce

Run mypy (without any arguments) on this script:

import enum

class C:
    pass

class D(C, enum.IntFlag):
    pass

Expected behaviour

mypy should print

Success: no issues found in 1 source file

Actual behaviour

mypy prints three error messages:

mypy-error.py:6: error: Definition of "__xor__" in base class "int" is incompatible with definition in base class "Flag"
mypy-error.py:6: error: Definition of "__or__" in base class "int" is incompatible with definition in base class "Flag"
mypy-error.py:6: error: Definition of "__and__" in base class "int" is incompatible with definition in base class "Flag"
Found 3 errors in 1 file (checked 1 source file)

Comments

The error messages go away when

  • Not using multiple inheritance, i.e. class D(enum.IntFlag) instead of class D(C, enum.IntFlag).
  • Or: when using enum.Flag instead of enum.IntFlag
@JukkaL JukkaL added bug mypy got something wrong false-positive mypy gave an error on correct code labels Sep 11, 2020
@JukkaL
Copy link
Collaborator

JukkaL commented Sep 11, 2020

This looks like a bug in type checking classes with multiple inheritance. You can use # type: ignore on line 6 as a workaround for now.

dreinon pushed a commit to supabase/postgrest-py that referenced this issue Jan 4, 2022
dreinon added a commit to supabase/postgrest-py that referenced this issue Jan 28, 2022
* add poetry dependency

* create APIResponse model

* return APIResponse model in execute method

* sort imports

* mypy bug workaround (python/mypy#9319)

* split logic, validate error existance and better type APIResponse

* Implement APIError

* add missing black config in pre-commit config

* type APIError properties

* fix: rm unused code and use returning param in update

* refactor: reorder lines

* chore: rebuild sync

* chore: rebuild poetry.lock

* fix: remove wrong parameter

* chore: format

* Chore: add missing return types

Co-authored-by: Anand <[email protected]>

* chore: replace builtin dict by Dict to support python < 3.9

* chore: update precommit hooks

* chore: apply format

* update return type in execute method

* use relative import

* add link to mypy issue

* switch super init by class init to avoid future errors

* chore: apply future annotations notation to return

* chore: rebuild sync

* tests: Add tests for response model (#74)

* initial commit

* tests: add fixtures for APIResponse

* tests: [WIP] Test methods that don't interact with RequestResponse

* tests: replace builtin type by typing type and add type annotations

* tests: add requests Response fixtures

* chore: change return order to improve readability

* tests: add tests for left methods

Co-authored-by: Joel Lee <[email protected]>
Co-authored-by: Dani Reinón <[email protected]>

* chore: modify ValueError with ValidationError

* chore: add "_" to internal methods

Co-authored-by: Anand <[email protected]>
Co-authored-by: Lee Yi Jie Joel <[email protected]>
Co-authored-by: Joel Lee <[email protected]>
kevinyamauchi added a commit to kevinyamauchi/napari-matplotlib that referenced this issue May 23, 2022
@adambirds
Copy link

Is this related to this issue here? Is there any idea when a proper fix will be available?

@benbovy
Copy link

benbovy commented Sep 7, 2023

Is there any update on this?

Alternatively to adding # type: ignore, another workaround is to redefine the problematic methods in the subclass with a simple call to super. That's not pretty either but that prevents ignoring the whole inheritance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code
Projects
None yet
4 participants