Define LockFile in exactly one place with clear logic. Fixes F811.
@@ -33,7 +33,7 @@ class UnlockError(LockError):
# first, a default, naive locking implementation
-class LockFile(object):
+class NaiveLockFile(object):
"""
A default, naive locking implementation. Always fails if the file
@@ -124,10 +124,6 @@ class WindowsLockFile(SystemLockFile):
raise UnlockError(self.fp.name)
-if 'msvcrt' in globals():
- LockFile = WindowsLockFile # noqa: F811
-
-
class UnixLockFile(SystemLockFile):
def _lock_file(self):
@@ -140,5 +136,8 @@ class UnixLockFile(SystemLockFile):
# no need to implement _unlock_file, it will be unlocked on close()
-if 'fcntl' in globals():
- LockFile = UnixLockFile
+LockFile = (
+ UnixLockFile if 'fcntl' in globals() else
+ WindowsLockFile if 'msvcrt' in globals() else
+ NaiveLockFile
+)
