Combining Flag members with |, & and ^ always walks both operands to check that neither carries a None value, raising a clear TypeError when one does. That check only matters in the rare case where a value really is None; for every normal combination of two valid flags it adds work to each operation.
Flag arithmetic is hot wherever flags model option sets. The re module's own flags are an IntFlag, so every re.compile(pattern, re.I | re.M) combines flags; permission systems, feature toggles and styling layers do the same in tight loops.
Running flag combinations mined from the top-1000 corpus, including the re flag sets, takes 72.6 µs today and 49.5 µs when the guard runs only when a value is actually None, 47% faster. The TypeError and its message are unchanged for the invalid cases.
Combining
Flagmembers with|,&and^always walks both operands to check that neither carries aNonevalue, raising a clearTypeErrorwhen one does. That check only matters in the rare case where a value really isNone; for every normal combination of two valid flags it adds work to each operation.Flag arithmetic is hot wherever flags model option sets. The
remodule's own flags are anIntFlag, so everyre.compile(pattern, re.I | re.M)combines flags; permission systems, feature toggles and styling layers do the same in tight loops.Running flag combinations mined from the top-1000 corpus, including the
reflag sets, takes 72.6 µs today and 49.5 µs when the guard runs only when a value is actuallyNone, 47% faster. TheTypeErrorand its message are unchanged for the invalid cases.