Returns 1 if `o` is considered a sequence for the purposes of Flatten(). Returns 0 otherwise. Returns -1 if an error occurred.
| 291 | // Returns 0 otherwise. |
| 292 | // Returns -1 if an error occurred. |
| 293 | int IsSequenceHelper(PyObject* o) { |
| 294 | // We treat dicts and other mappings as special cases of sequences. |
| 295 | if (IsMappingHelper(o)) return true; |
| 296 | if (IsMappingViewHelper(o)) return true; |
| 297 | if (IsAttrsHelper(o)) return true; |
| 298 | if (PySet_Check(o) && !WarnedThatSetIsNotSequence) { |
| 299 | LOG(WARNING) << "Sets are not currently considered sequences, " |
| 300 | "but this may change in the future, " |
| 301 | "so consider avoiding using them."; |
| 302 | WarnedThatSetIsNotSequence = true; |
| 303 | } |
| 304 | static auto* const check_cache = new CachedTypeCheck([](PyObject* to_check) { |
| 305 | int is_instance = IsInstanceOfRegisteredType(to_check, "Sequence"); |
| 306 | |
| 307 | // Don't cache a failed is_instance check. |
| 308 | if (is_instance == -1) return -1; |
| 309 | |
| 310 | return static_cast<int>(is_instance != 0 && !IsString(to_check)); |
| 311 | }); |
| 312 | return check_cache->CachedLookup(o); |
| 313 | } |
| 314 | |
| 315 | // ValueIterator interface |
| 316 | class ValueIterator { |
no test coverage detected