Skip to content

bpo-46730: Fix refleak and tighten NULL checks - #31389

Merged
sweeneyde merged 1 commit into
python:mainfrom
tiran:bpo-46730-refleak
Feb 17, 2022
Merged

sweeneyde merged 1 commit into
python:mainfrom
tiran:bpo-46730-refleak

Conversation

@tiran

@tiran tiran commented Feb 17, 2022 •

Copy link
Copy Markdown
Member

PyType_GetQualName returns a new reference.

Signed-off-by: Christian Heimes christian@python.org

https://bugs.python.org/issue46730

``PyType_GetQualName`` returns a new reference.

Signed-off-by: Christian Heimes <christian@python.org>
@sweeneyde

Copy link
Copy Markdown
Member

I'll try to be more cautious about ref-leaks in the future. Thanks for catching this!

@markshannon
markshannon marked this pull request as ready for review February 17, 2022 16:41
@markshannon markshannon added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Feb 17, 2022
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @markshannon for commit a22802e 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Feb 17, 2022
@tiran

tiran commented Feb 17, 2022

Copy link
Copy Markdown
Member Author

@sweeneyde The buildbots have not finished verifying this PR yet. Next time please wait until all buildbots are successful.

@sweeneyde

Copy link
Copy Markdown
Member

Ah, my apologies, I was just looking at the refleak bots. I will wait next time. Thank you for the help!

@Alex-Blade

Copy link
Copy Markdown
Contributor

Oh, apologies, should have checked that

@geryogam

Copy link
Copy Markdown
Contributor

@tiran In which case could you have the last error message "AttributeError: property has no getter" that you introduced in the else clause? In other words, when does PyType_GetQualName(Py_TYPE(obj)) return NULL in C?

I can’t get that error message by making hasattr(type(obj), "__qualname__") return False in Python:

class M(type):
    def __getattribute__(self, name): raise AttributeError

class A(metaclass=M): pass

obj = A()
hasattr(type(obj), "__qualname__") # returns False
property().__get__(obj)  # raises AttributeError: property of 'A' object has no getter

It seems that property().__get__(obj) uses vars(type)["__qualname__"].__get__(type(obj)) (which returns 'A') and not type(obj).__qualname__ (which raises AttributeError) to get the __qualname__ attribute of type(obj).

So is your else clause dead code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

8 participants