Skip to content

Commit 95451ce

Browse files
author
Sagar Mittal
committed
Perform an exact type check rather tha instanceof
1 parent 56e5886 commit 95451ce

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

python/pyspark/sql/streaming/stateful_processor_api_client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import json
2020
import os
2121
import socket
22-
from types import NoneType
2322
from typing import IO, Any, Dict, List, Union, Optional, Tuple, Iterator, cast
2423

2524
from pyspark.serializers import write_int, read_int, UTF8Deserializer
@@ -39,10 +38,10 @@
3938
import numpy as np
4039

4140
has_numpy = True
41+
SCALAR_TYPES = frozenset((bool, int, float, str, bytes, datetime, type(None)))
4242

4343
def _normalize_state_value(v: Any) -> Any:
44-
# Fast path for common scalar values.
45-
if isinstance(v, (bool, int, float, str, bytes, datetime, NoneType)):
44+
if type(v) in SCALAR_TYPES: # Fast path for common scalar values.
4645
return v
4746
# Convert NumPy scalar values to Python primitive values.
4847
if isinstance(v, np.generic):

0 commit comments

Comments
 (0)