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

MethodType uses FunctionLike types inconsistently #11200

Closed
tyralla opened this issue Dec 26, 2023 · 0 comments · Fixed by #11201
Closed

MethodType uses FunctionLike types inconsistently #11200

tyralla opened this issue Dec 26, 2023 · 0 comments · Fixed by #11201

Comments

@tyralla
Copy link
Contributor

tyralla commented Dec 26, 2023

Since version 1.8, Mypy does not intersect types in isinstance checks if at least one is final. In my code base, this leads to unexpected unreachable warnings. I could narrow them down to:

from types import MethodType

m: MethodType
if isinstance(m.__func__, MethodType):  # error: Subclass of "FunctionType" and "MethodType" cannot exist: "FunctionType" is final  [unreachable] \
                                        # error: Subclass of "FunctionType" and "MethodType" cannot exist: "MethodType" is final  [unreachable]
    m = m.__func__  # error: Statement is unreachable  [unreachable]

As I implemented the Mypy change, I double-checked that I did not break something. But it seems the definition of MethodType in typeshed is inconsistent. Its __init__ method accepts Callable (#1499), but its __func__ attribute returns FunctionType (#1383). As MethodType can accept and return other methods at runtime, it seems right to define the return type as Callable, too.

tyralla added a commit to hydpy-dev/hydpy that referenced this issue Jan 8, 2024
…2submethodnames_automethod` of class `PyxWriter` of module `modelutils` (see python/typeshed#11200).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant