Reformatted files
This commit is contained in:
parent
b376fe6b7a
commit
ce13d065c0
|
@ -1,8 +1,9 @@
|
||||||
import sys
|
import sys
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import Dict, Callable, List, Final
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from types import FrameType
|
from types import FrameType
|
||||||
|
from typing import Callable, Dict, Final, List
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ConstantValue:
|
class ConstantValue:
|
||||||
|
@ -10,12 +11,17 @@ class ConstantValue:
|
||||||
name: str
|
name: str
|
||||||
value: object
|
value: object
|
||||||
|
|
||||||
|
|
||||||
def _traceFun(frame: FrameType, event: str, arg: object) -> None:
|
def _traceFun(frame: FrameType, event: str, arg: object) -> None:
|
||||||
for constant in constMap[frame]:
|
for constant in constMap[frame]:
|
||||||
if constant.name in frame.f_locals and frame.f_locals[constant.name] != constant.value:
|
if (
|
||||||
|
constant.name in frame.f_locals
|
||||||
|
and frame.f_locals[constant.name] != constant.value
|
||||||
|
):
|
||||||
frame.f_locals[constant.name] = constant.value
|
frame.f_locals[constant.name] = constant.value
|
||||||
raise SyntaxError(f"Cannot assign value to constant {repr(constant.name)}")
|
raise SyntaxError(f"Cannot assign value to constant {repr(constant.name)}")
|
||||||
|
|
||||||
|
|
||||||
class _ConstClass:
|
class _ConstClass:
|
||||||
def __setattr__(self, name, value):
|
def __setattr__(self, name, value):
|
||||||
"""This is the method called when a new constant is created"""
|
"""This is the method called when a new constant is created"""
|
||||||
|
|
2
test.py
2
test.py
|
@ -1,6 +1,8 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pyconstants import const
|
from pyconstants import const
|
||||||
|
|
||||||
|
|
||||||
def test_costant():
|
def test_costant():
|
||||||
# It's not that complex, why am I even writing tests?
|
# It's not that complex, why am I even writing tests?
|
||||||
const.myvar = 5
|
const.myvar = 5
|
||||||
|
|
Loading…
Reference in New Issue