Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bpo-28869: Skip one additional frame when type.__new__ is called not directly from type.__call__. #14166

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Jun 17, 2019

* Move handling of one-argument call of type() from type.__new__() to type.__call__().
* Move deducing __module__ from the caller's frame from type.__new__() to type.__call__().
@brettcannon brettcannon added the type-bug An unexpected behavior, bug, or error label Jun 21, 2019
@ilevkivskyi
Copy link
Member

@serhiy-storchaka I like this approach, please let me know when this is ready for review (I assume tests are needed and some comments explaining this behavior).

@serhiy-storchaka
Copy link
Member Author

Yes, it needs tests and documenting.

Also this PR contains actually two changes. I am not sure that both of them should be backported, but it is difficult to make one without making other.

@serhiy-storchaka
Copy link
Member Author

I just have tested, and seems there is no undesired behavior change. So I just need to write tests and a NEWS entry.

@serhiy-storchaka
Copy link
Member Author

Unfortunately it does not work. Not setting __module__ in the class dictionary does not help with the original issue, because __module__ will be looked up in the metaclass dictionary. Setting it in __call__() opens other questions and significantly complicates the code.

@serhiy-storchaka serhiy-storchaka changed the title [WIP] bpo-28869: Change some details in type(). bpo-28869: Skip one additional frame when type.__new__ is called not directly from type.__call__. Oct 13, 2019
Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

I have one question/comment. Also if we are going this way, I think this deserves a comment in the code explaining the motivation.

}
while (depth-- > 0 && f->f_back) {
f = f->f_back;
}
Copy link
Member

Choose a reason for hiding this comment

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

Unless I am missing something, depth can be only either 0 or 1, maybe it is better to use a name like skip or nested and write this as:

if (skip_frame && f->f_back) {
    f = f->f_back;
}

@ilevkivskyi
Copy link
Member

It looks like this may also fix https://bugs.python.org/issue37948

@serhiy-storchaka
Copy link
Member Author

I am not sure it is a good solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review DO-NOT-MERGE type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants