-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
False positive about self argument with union of namedtuple and Any #15600
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
Comments
Note that the bug is specific to a union with But the problem is actually much wider, Unfortunately, switching |
The hack to use `meet_types(original_type, itype)` to select a correct element from a union appeared before we added proper handling of unions in various places related to `checkmember.py`. This is error prone, since `meet_types()` is one of least precise type ops (for good and bad reasons), and results in obscure bugs, see e.g. #15600 This hack should not be needed anymore, now we have three-level information available everywhere we needed it: * `original_type` - as the name says, a type from which everything started. This is used for error messages and for plugin hooks. * `self_type` - a specific element of the union is the original type is a union. The name is because this is what will be ultimately used by `bind_self()` * `itype` the actual instance type where we look up the attribute (this will be e.g. a fallback if the `self_type` is not an instance)
The hack to use `meet_types(original_type, itype)` to select a correct element from a union appeared before we added proper handling of unions in various places related to `checkmember.py`. This is error prone, since `meet_types()` is one of least precise type ops (for good and bad reasons), and results in obscure bugs, see e.g. python#15600 This hack should not be needed anymore, now we have three-level information available everywhere we needed it: * `original_type` - as the name says, a type from which everything started. This is used for error messages and for plugin hooks. * `self_type` - a specific element of the union is the original type is a union. The name is because this is what will be ultimately used by `bind_self()` * `itype` the actual instance type where we look up the attribute (this will be e.g. a fallback if the `self_type` is not an instance)
Fixes python#15600 The issue was previously "fixed" because of another bug. Now that everything is properly fixed, we can add this "regression" test just in case.
The hack to use `meet_types(original_type, itype)` to select a correct element from a union appeared before we added proper handling of unions in various places related to `checkmember.py`. This is error prone, since `meet_types()` is one of least precise type ops (for good and bad reasons), and results in obscure bugs, see e.g. python#15600 This hack should not be needed anymore, now we have three-level information available everywhere we needed it: * `original_type` - as the name says, a type from which everything started. This is used for error messages and for plugin hooks. * `self_type` - a specific element of the union is the original type is a union. The name is because this is what will be ultimately used by `bind_self()` * `itype` the actual instance type where we look up the attribute (this will be e.g. a fallback if the `self_type` is not an instance)
Fixes python#15600 The issue was previously "fixed" because of another bug. Now that everything is properly fixed, we can add this "regression" test just in case.
The hack to use `meet_types(original_type, itype)` to select a correct element from a union appeared before we added proper handling of unions in various places related to `checkmember.py`. This is error prone, since `meet_types()` is one of least precise type ops (for good and bad reasons), and results in obscure bugs, see e.g. python#15600 This hack should not be needed anymore, now we have three-level information available everywhere we needed it: * `original_type` - as the name says, a type from which everything started. This is used for error messages and for plugin hooks. * `self_type` - a specific element of the union is the original type is a union. The name is because this is what will be ultimately used by `bind_self()` * `itype` the actual instance type where we look up the attribute (this will be e.g. a fallback if the `self_type` is not an instance)
Fixes python#15600 The issue was previously "fixed" because of another bug. Now that everything is properly fixed, we can add this "regression" test just in case.
The following code produces a false positive:
It looks like the self argument check fails when we have a union with a namedtuple type. It's okay if the base class is a regular class, or if there is no union.
The text was updated successfully, but these errors were encountered: