diff options
| author | Alex Waygood <Alex.Waygood@Gmail.com> | 2024-01-05 01:01:48 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-05 01:01:48 (GMT) |
| commit | ed6ea3ea79fac68b127c7eb457c7ecb996461010 (patch) | |
| tree | 956604543a694556b838c54e9650fb2f8bc2e93e /Lib/test/test_pathlib/test_pathlib_abc.py | |
| parent | fcb3c2a444709d2a53faa20c5b43541674064018 (diff) | |
| download | cpython-ed6ea3ea79fac68b127c7eb457c7ecb996461010.zip cpython-ed6ea3ea79fac68b127c7eb457c7ecb996461010.tar.gz cpython-ed6ea3ea79fac68b127c7eb457c7ecb996461010.tar.bz2 | |
gh-113320: Reduce the number of dangerous `getattr()` calls when constructing protocol classes (#113401)
- Only attempt to figure out whether protocol members are "method members" or not if the class is marked as a runtime protocol. This information is irrelevant for non-runtime protocols; we can safely skip the risky introspection for them.
- Only do the risky getattr() calls in one place (the runtime_checkable class decorator), rather than in three places (_ProtocolMeta.__init__, _ProtocolMeta.__instancecheck__ and _ProtocolMeta.__subclasscheck__). This reduces the number of locations in typing.py where the risky introspection could go wrong.
- For runtime protocols, if determining whether a protocol member is callable or not fails, give a better error message. I think it's reasonable for us to reject runtime protocols that have members which raise strange exceptions when you try to access them. PEP-544 clearly states that all protocol member must be callable for issubclass() calls against the protocol to be valid -- and if a member raises when we try to access it, there's no way for us to figure out whether it's a callable member or not!
Diffstat (limited to 'Lib/test/test_pathlib/test_pathlib_abc.py')
0 files changed, 0 insertions, 0 deletions
