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

Add __code__ to types.MethodType #12749

Merged
merged 2 commits into from
Oct 8, 2024

Conversation

Avasam
Copy link
Collaborator

@Avasam Avasam commented Oct 6, 2024

I have no idea if this is even correct. But here's the PR that made me add this: mhammond/pywin32#2385 and here's a short repro:

import types

class A:
    def test(self): ...

print(type(A().test) is types.MethodType)
print(A().test.__code__)
A().test.__code__ = None

results in:

True
<code object test at 0x00000236894BB660, file "c:\Users\Avasam\Desktop\import types.py", line 4>
Traceback (most recent call last):
  File "c:\Users\Avasam\Desktop\import types.py", line 8, in <module>
    A().test.__code__ = None
AttributeError: 'method' object has no attribute '__code__'

Copy link
Contributor

github-actions bot commented Oct 6, 2024

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

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.

This is a weird one, but the change look kinda correct to me.

@srittau srittau merged commit 1f4031c into python:main Oct 8, 2024
63 checks passed
@Avasam Avasam deleted the Add-__code__-to-MethodType branch October 8, 2024 12:02
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.

2 participants