Skip to content

Commit 119fb02

Browse files
nkpro2000srbessman
authored andcommitted
Fix classproperty issue
1 parent f6f999c commit 119fb02

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

pslab/bus/spi.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
0
2020
"""
2121

22+
import sys
2223
from typing import List, Tuple
2324

2425
import pslab.protocol as CP
@@ -37,6 +38,21 @@
3738
_SMP = 1
3839

3940

41+
class classmethod_(classmethod):
42+
"""Support chaining classmethod and property."""
43+
44+
def __init__(self, f):
45+
self.f = f
46+
super().__init__(f)
47+
48+
def __get__(self, obj, cls=None):
49+
# classmethod() to support chained decorators; new in python 3.9.
50+
if sys.version_info < (3, 9) and isinstance(self.f, property):
51+
return self.f.__get__(cls)
52+
else:
53+
return super().__get__(obj, cls)
54+
55+
4056
class _SPIPrimitive:
4157
"""SPI primitive commands.
4258
@@ -69,15 +85,15 @@ class _SPIPrimitive:
6985
def __init__(self, device: SerialHandler = None):
7086
self._device = device if device is not None else SerialHandler()
7187

72-
@classmethod
88+
@classmethod_
7389
@property
7490
def _frequency(cls) -> float:
7591
ppre = cls._PPRE_MAP[cls._primary_prescaler]
7692
spre = cls._SPRE_MAP[cls._secondary_prescaler]
7793

7894
return CP.CLOCK_RATE / (ppre * spre)
7995

80-
@classmethod
96+
@classmethod_
8197
@property
8298
def _clock_phase(cls) -> int:
8399
return (cls._clock_edge ^ 1) & 1

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy