Skip to content

Commit

Permalink
Simplify portable os.O_BINARY access
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Dec 20, 2024
1 parent aa98f31 commit 78c765b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion chess/polyglot.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class MemoryMappedReader:
"""Maps a Polyglot opening book to memory."""

def __init__(self, filename: StrOrBytesPath) -> None:
fd = os.open(filename, os.O_RDONLY | os.O_BINARY if hasattr(os, "O_BINARY") else os.O_RDONLY)
fd = os.open(filename, os.O_RDONLY | getattr(os, "O_BINARY", 0))
try:
self.mmap: Union[mmap.mmap, _EmptyMmap] = mmap.mmap(fd, 0, access=mmap.ACCESS_READ)
except (ValueError, OSError):
Expand Down
2 changes: 1 addition & 1 deletion chess/syzygy.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ def __init__(self, path: str, *, variant: Type[chess.Board] = chess.Board) -> No

def init_mmap(self) -> None:
if self.data is None:
fd = os.open(self.path, os.O_RDONLY | os.O_BINARY if hasattr(os, "O_BINARY") else os.O_RDONLY)
fd = os.open(self.path, os.O_RDONLY | getattr(os, "O_BINARY", 0))
try:
data = mmap.mmap(fd, 0, access=mmap.ACCESS_READ)
finally:
Expand Down

0 comments on commit 78c765b

Please sign in to comment.