From 51831f13c668984c5dc0707c5f129c848db7b21f Mon Sep 17 00:00:00 2001 From: Benedikt Bartscher Date: Thu, 30 Jan 2025 15:30:34 +0100 Subject: [PATCH] fix PGH003, i love it --- benchmarks/benchmark_pickle.py | 8 ++++---- reflex/state.py | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/benchmarks/benchmark_pickle.py b/benchmarks/benchmark_pickle.py index c282874b8..d03c21a42 100644 --- a/benchmarks/benchmark_pickle.py +++ b/benchmarks/benchmark_pickle.py @@ -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) diff --git a/reflex/state.py b/reflex/state.py index 439d2dfb5..89093deb0 100644 --- a/reflex/state.py +++ b/reflex/state.py @@ -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