Skip to content

add types.MethodType.__get__ on py313+ #14190

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

Merged
merged 3 commits into from
May 30, 2025

Conversation

jorenham
Copy link
Contributor

runtime behavior (3.13):

>>> class A:
...     def f(self): ...
...     
>>> f = A().f
>>> f.__get__(object()) is f
True
>>> f.__get__(object(), object) is f
True
>>> f.__get__(object(), None) is f
True
>>> f.__get__(object, None) is f
True
>>> f.__get__(object) is f
True

related to https://discuss.python.org/t/when-should-we-assume-callable-types-are-method-descriptors/92938

@jorenham jorenham changed the title add types.MethodType.__get__ add types.MethodType.__get__ on py313+ May 29, 2025

This comment has been minimized.

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove the extra newlines that were probably inserted by your autoformatter?

@jorenham
Copy link
Contributor Author

Could you remove the extra newlines that were probably inserted by your autoformatter?

ah yes sorry about that; rookie mistake

Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

archinstall (https://github.com/archlinux/archinstall)
- ./archinstall/tui/curses_menu.py:710: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
- https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
- Please report a bug at https://github.com/python/mypy/issues
- version: 1.15.0
- ./archinstall/tui/curses_menu.py:710: : note: use --pdb to drop into pdb
- Traceback (most recent call last):
-   File "mypy/checkexpr.py", line 5903, in accept
-   File "mypy/nodes.py", line 1889, in accept
-   File "mypy/checkexpr.py", line 3284, in visit_member_expr
-   File "mypy/checkexpr.py", line 3309, in analyze_ordinary_member_access
-   File "mypy/checkmember.py", line 207, in analyze_member_access
-   File "mypy/checkmember.py", line 226, in _analyze_member_access
-   File "mypy/checkmember.py", line 344, in analyze_instance_member_access
-   File "mypy/meet.py", line 96, in meet_types
-   File "mypy/subtypes.py", line 223, in is_proper_subtype
-   File "mypy/subtypes.py", line 351, in _is_subtype
-   File "mypy/types.py", line 1469, in accept
-   File "mypy/subtypes.py", line 581, in visit_instance
-   File "mypy/subtypes.py", line 2095, in infer_class_variances
-   File "mypy/subtypes.py", line 2057, in infer_variance
-   File "mypy/subtypes.py", line 186, in is_subtype
-   File "mypy/subtypes.py", line 351, in _is_subtype
-   File "mypy/types.py", line 3033, in accept
-   File "mypy/subtypes.py", line 1079, in visit_partial_type
- RuntimeError: Partial type "<partial list[?]>" cannot be checked with "issubtype()"

@jorenham
Copy link
Contributor Author

jorenham commented May 30, 2025

@JelleZijlstra
Copy link
Member

Interestingly that crash also went away with #14198, which suggests it's a case of nondeterminism in mypy.

@srittau
Copy link
Collaborator

srittau commented May 30, 2025

Primer passed previously.

@srittau srittau merged commit a92ecca into python:main May 30, 2025
64 checks passed
@jorenham jorenham deleted the types.MethodType.__get__ branch May 30, 2025 16:31
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 this pull request may close these issues.

3 participants