see if this class has "canned" roles based on a known collection type (dict, set, list). Apply those roles as needed to the "roles" dictionary, and also prepare "decorator" methods
(cls, roles, methods)
| 885 | |
| 886 | |
| 887 | def _setup_canned_roles(cls, roles, methods): |
| 888 | """see if this class has "canned" roles based on a known |
| 889 | collection type (dict, set, list). Apply those roles |
| 890 | as needed to the "roles" dictionary, and also |
| 891 | prepare "decorator" methods |
| 892 | |
| 893 | """ |
| 894 | collection_type = util.duck_type_collection(cls) |
| 895 | if collection_type in __interfaces: |
| 896 | assert collection_type is not None |
| 897 | canned_roles, decorators = __interfaces[collection_type] |
| 898 | for role, name in canned_roles.items(): |
| 899 | roles.setdefault(role, name) |
| 900 | |
| 901 | # apply ABC auto-decoration to methods that need it |
| 902 | for method, decorator in decorators.items(): |
| 903 | fn = getattr(cls, method, None) |
| 904 | if ( |
| 905 | fn |
| 906 | and method not in methods |
| 907 | and not hasattr(fn, "_sa_instrumented") |
| 908 | ): |
| 909 | setattr(cls, method, decorator(fn)) |
| 910 | |
| 911 | |
| 912 | def _assert_required_roles(cls, roles, methods): |
no test coverage detected