Skip to content

Commit

Permalink
Merge pull request #628 from bashtage/clean-code
Browse files Browse the repository at this point in the history
TYP: Fix typing support
  • Loading branch information
bashtage authored Nov 6, 2024
2 parents 7f29b34 + cfc6829 commit 3111b39
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions linearmodels/iv/absorbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from collections import defaultdict
from collections.abc import Hashable, Iterable
from hashlib import sha256
import hashlib
from typing import Any, DefaultDict, Union, cast
import warnings

Expand Down Expand Up @@ -70,18 +70,20 @@

class Hasher:
def __init__(self):
self._hasher: hashlib._Hash | xxh64
if HAVE_XXHASH:
self._hasher = xxh64()
self._use_xx = True
self._use_xxh64 = True
else:
self._hasher = sha256()
self._use_xx = False
self._hasher = hashlib.sha256()
self._use_xxh64 = False

def reset(self):
if self._use_xx:
self._hasher = xxh64()
else:
if self._use_xxh64:
assert isinstance(self._hasher, xxh64)
self._hasher.reset()
else:
self._hasher = hashlib.sha256()

def update(self, data: memoryview) -> None:
self._hasher.update(data)
Expand Down

0 comments on commit 3111b39

Please sign in to comment.