Skip to content

Commit 62dd9e9

Browse files
nkpro2000srbessman
authored andcommitted
Move classmethod_ to init
1 parent 7824e6b commit 62dd9e9

File tree

3 files changed

+23
-36
lines changed

3 files changed

+23
-36
lines changed

pslab/bus/__init__.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
"""Contains modules for interfacing with the PSLab's I2C, SPI, and UART buses."""
22

3-
from pslab.bus.i2c import I2CMaster, I2CSlave
4-
from pslab.bus.spi import SPIMaster, SPISlave
5-
from pslab.bus.uart import UART
3+
import sys
4+
5+
6+
class classmethod_(classmethod):
7+
"""Support chaining classmethod and property."""
8+
9+
def __init__(self, f):
10+
self.f = f
11+
super().__init__(f)
12+
13+
def __get__(self, obj, cls=None):
14+
# classmethod() to support chained decorators; new in python 3.9.
15+
if sys.version_info < (3, 9) and isinstance(self.f, property):
16+
return self.f.__get__(cls)
17+
else:
18+
return super().__get__(obj, cls)
19+
20+
21+
from pslab.bus.i2c import I2CMaster, I2CSlave # noqa: E402
22+
from pslab.bus.spi import SPIMaster, SPISlave # noqa: E402
23+
from pslab.bus.uart import UART # noqa: E402
624

725
__all__ = (
826
"I2CMaster",

pslab/bus/spi.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
0
2020
"""
2121

22-
import sys
2322
from typing import List, Tuple
2423

2524
import pslab.protocol as CP
25+
from pslab.bus import classmethod_
2626
from pslab.serial_handler import SerialHandler
2727

2828
__all__ = (
@@ -38,21 +38,6 @@
3838
_SMP = 1
3939

4040

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-
5641
class _SPIPrimitive:
5742
"""SPI primitive commands.
5843

pslab/bus/uart.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,17 @@
1313
>>> bus.write_byte(0x55)
1414
"""
1515

16-
import sys
1716
from typing import Tuple
1817

1918
import pslab.protocol as CP
19+
from pslab.bus import classmethod_
2020
from pslab.serial_handler import SerialHandler
2121

2222
__all__ = "UART"
2323
_BRGVAL = 0x22 # BaudRate = 460800.
2424
_MODE = (0, 0) # 8-bit data and no parity, 1 stop bit.
2525

2626

27-
class classmethod_(classmethod):
28-
"""Support chaining classmethod and property."""
29-
30-
def __init__(self, f):
31-
self.f = f
32-
super().__init__(f)
33-
34-
def __get__(self, obj, cls=None):
35-
"""Check python version and return appropriate getter."""
36-
# classmethod() to support chained decorators; new in python 3.9.
37-
if sys.version_info < (3, 9) and isinstance(self.f, property):
38-
return self.f.__get__(cls)
39-
else:
40-
return super().__get__(obj, cls)
41-
42-
4327
class _UARTPrimitive:
4428
"""UART primitive commands.
4529

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