fix PGH003, i love it

This commit is contained in:
Benedikt Bartscher 2025-01-30 15:30:34 +01:00
parent 9d40c25a9c
commit 51831f13c6
No known key found for this signature in database
2 changed files with 10 additions and 10 deletions

View File

@ -109,10 +109,10 @@ def test_pickle(
pytest.skip("Blosc is not available.")
def dump(obj: State) -> bytes:
return compress(pickle.dumps(obj, protocol=protocol)) # type: ignore
return compress(pickle.dumps(obj, protocol=protocol)) # pyright: ignore[reportReturnType]
def load(data: bytes) -> State:
return pickle.loads(decompress(data)) # type: ignore
return pickle.loads(decompress(data)) # pyright: ignore[reportAny,reportArgumentType]
else:
@ -134,7 +134,7 @@ def test_pickle(
def run(obj: State) -> None:
_ = redis_client.set(key, dump(obj))
_ = load(redis_client.get(key)) # type: ignore
_ = load(redis_client.get(key)) # pyright: ignore[reportArgumentType]
else:
@ -149,7 +149,7 @@ def test_pickle(
benchmark.extra_info["size"] = size
benchmark.extra_info["redis"] = redis
benchmark.extra_info["pickle_protocol"] = protocol
redis_group = redis.__name__ if redis else "no_redis" # type: ignore
redis_group = redis.__name__ if redis else "no_redis" # pyright: ignore[reportUnknownMemberType,reportAttributeAccessIssue,reportUnknownVariableType]
benchmark.group = f"{redis_group}_{big_state_size[1]}"
_ = benchmark(run, big_state)

View File

@ -2314,7 +2314,7 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
prefix = STATE_COMPRESSED
else:
prefix = STATE_NOT_COMPRESSED
payload = prefix + payload # type: ignore
payload = prefix + payload # pyright: ignore[reportOperatorIssue,reportUnknownVariableType]
return payload
@ -2346,8 +2346,8 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
if is_compressed:
from blosc2 import decompress
data = decompress(data) # type: ignore
data = pickle.loads(data) # type: ignore
data = decompress(data) # pyright: ignore[reportAssignmentType]
data = pickle.loads(data) # pyright: ignore[reportArgumentType]
elif fp is not None and data is None:
if environment.REFLEX_COMPRESS_STATE.get():
# read first byte to determine if compressed
@ -2363,13 +2363,13 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
fp = BytesIO()
for chunk_index in range(schunk.nchunks):
fp.write(schunk.decompress_chunk(chunk_index)) # type: ignore
fp.write(schunk.decompress_chunk(chunk_index)) # pyright: ignore[reportArgumentType,reportUnusedCallResult]
data = pickle.load(fp)
else:
raise ValueError("Only one of `data` or `fp` must be provided")
substate_schema, state = data # type: ignore
if substate_schema != state._to_schema(): # type: ignore
substate_schema, state = data # pyright: ignore[reportUnknownVariableType,reportGeneralTypeIssues]
if substate_schema != state._to_schema(): # pyright: ignore[reportAttributeAccessIssue,reportUnknownMemberType]
raise StateSchemaMismatchError()
return state # type: ignore