鉴于现有 npm 软件包中最近出现的恶意软件,我希望有一种机制可以让我在安装新软件包或更新现有软件包之前进行一些基本检查。我的主要问题是直接安装的软件包和间接安装的软件包。
一般来说,我想在安装之前获取 npm 将安装的软件包版本列表。更具体地说,我想要安装的软件包的年龄,因此如果其中任何一个软件包的年龄小于一天,我可以生成警告。
如果我可以直接使用 npm 来做到这一点,那就太好了,但恐怕我需要围绕它编写一些脚本。
具体用例:
如果我npm install react-native-gesture-handler在 2021 年 10 月 22 日执行,它将执行恶意版本的 ua-parser 的安装后挂钩,并且我的计算机将受到损害,这是我想避免的事情。
当我输入时npm install react-native-gesture-handler --dry-run,它只告诉我它将安装哪个版本的react-native-gesture-handler,但它不会告诉我它将安装当天发布的ua-parser版本。
补充笔记:
npm i --dry-run存在,但它只显示直接包。npm list存在,但它只显示安装后的软件包(因此在安装挂钩已经造成伤害之后)我正在尝试在 jupyter lab上重现官方的 Asynchronous Widgets-Example,但从未继续。await
docker run --rm -p 8888:8888 -e JUPYTER_ENABLE_LAB=yes jupyter/datascience-notebook start-notebook.sh --NotebookApp.token=''firefox 0.0.0.0:8888%gui asyncio
import asyncio
def wait_for_change(widget, value):
future = asyncio.Future()
def getvalue(change):
# make the new value available
future.set_result(change.new)
widget.unobserve(getvalue, value)
widget.observe(getvalue, value)
return future
from ipywidgets import IntSlider
slider = IntSlider()
async def f():
for i in range(10):
print('did work %s'%i)
#x = await asyncio.sleep(1)
x = await …Run Code Online (Sandbox Code Playgroud) 当参数可以具有从特定基类型派生的任何类型时,如何注释抽象方法的函数参数的类型?
例子:
import abc
import attr
@attr.s(auto_attribs=True)
class BaseConfig(abc.ABC):
option_base: str
@attr.s(auto_attribs=True)
class ConfigA(BaseConfig):
option_a: str
@attr.s(auto_attribs=True)
class ConfigB(BaseConfig):
option_b: bool
class Base(abc.ABC):
@abc.abstractmethod
def do_something(self, config: BaseConfig):
pass
class ClassA(Base):
def do_something(self, config: ConfigA):
# test.py:27: error: Argument 1 of "do_something" is incompatible with supertype "Base"; supertype defines the argument type as "BaseConfig"
print("option_a: " + config.option_a)
class ClassB(Base):
def do_something(self, config: ConfigB):
# test.py:33: error: Argument 1 of "do_something" is incompatible with supertype "Base"; supertype defines the argument …Run Code Online (Sandbox Code Playgroud) 背景:我正在为ipython创建一个魔术线.这种魔法只适用于行,其中函数的返回值被赋给变量.
我正在寻找一种方法来确保一行是python中有效的函数调用+赋值.
例如,接受以下内容:
a = b()
a,b = c(d,e="f")
a = b(c()+c)
Run Code Online (Sandbox Code Playgroud)
以下内容将被拒绝:
a = def fun() # no function call
b(a=2) # no assignment
a = b + c # no function call
a = b() + c() # top-level on right-hand-side must be function call
Run Code Online (Sandbox Code Playgroud)
如果该行根本不是有效的python,我不关心它是否通过,因为这将在另一个阶段处理.
ipywidgets ×1
jupyter-lab ×1
mypy ×1
node.js ×1
npm ×1
npm-install ×1
oop ×1
parsing ×1
python ×1
python-3.8 ×1
python-3.x ×1
regex ×1
security ×1