accrocchio是一个用来标记和接收臭味代码通知的库(也称为“accrocchio”)。

accrocchio的Python项目详细描述


build status

阿克罗奇奥

accrocchio是一个标记和接收臭味代码通知的库。 (又名“accrocchio”)。

示例

fromaccrocchio.badgeofshameimportaccrocchiofromaccrocchioimportobserversclassAClassThatSmells(metaclass=accrocchio):pass@accrocchiodefa_function_that_smells():passaccrocchio.how_many()# here we have 1, as you have declared a smelly classAClassThatSmells()accrocchio.how_many()# here we have 2, as you have created an instance of a smelly classa_function_that_smells()accrocchio.how_many()# here we have 3, as you have invoked a smelly functionaccrocchio.reset()accrocchio.how_many()# here we have 0# You can also be notified of smelly code execution, such as:classMyAccrocchioObserver(observers.AccrocchioObserver):defon_accrocchio(self):print('Another accrocchio!')defreset(self):print('Reset accrocchi')accrocchio.add_observer(MyAccrocchioObserver())a_function_that_smells()# prints 'Another accrocchio!'accrocchio.reset()# prints 'Reset accrocchi'

也可以装饰整个班级。两份声明 类的实例化增加了accrocchio计数器。

fromaccrocchio.badgeofshameimportaccrocchiofromaccrocchioimportobservers@accrocchioclassAClassThatSmells:passaccrocchio.how_many()# here we have 1, as you have declared a smelly classAClassThatSmells()accrocchio.how_many()# here we have 2, as you have created an instance of a smelly class

您可以使用类型提示声明accrocchio,如下所示:

fromaccrocchio.badgeofshameimportaccrocchio,detonatordeff(a:detonator[int]):passaccrocchio.how_many()# here we have 1, as you have declared a smelly parameterdetonator.how_many()# here we have 1, as you have declared a smelly parameterf(1)accrocchio.how_many()# here we still have 1detonator.how_many()# here we still have 1

库还实现Michael Duell’s resign patterns

fromaccrocchio.badgeofshameimportaccrocchio,detonator@accrocchiodefaccrocchio_fun():pass@detonatordefdetonator_fun():passaccrocchio_fun()accrocchio.how_many()# here we have 1, as you have invoked an accrocchio functiondetonator.how_many()# here we have 0, as you have never invoked a detonator functiondetonator_fun()detonator.how_many()# here we have 1, as you have invoked a detonator functionaccrocchio.how_many()# here we have 2, as you have invoked a detonator function, which is an accrocchio

您可以将任意代码标记为accrocchio:

fromaccrocchio.badgeofshameimportdetonator,epoxy,this_is_a,this_is_anthis_is_an(epoxy)this_is_a(detonator)detonator.how_many()# this will be 1epoxy.how_many()# this will be 1

如果需要将代码的特定部分标记为 accrocchio,您可以将其用作上下文管理器,如下所示:

fromaccrocchio.badgeofshameimportdetonator,epoxywithdetonator:...withepoxy:...detonator.how_many()# this will be 1epoxy.how_many()# this will be 1

有关已实现的accrocchio辞职模式的完整列表,请 咨询Michael Duell’s resign patterns

一些最后的注释:

  1. 只有当软件的一小部分是 阿克罗奇奥
  2. 我们故意忽略了3.5之前的python版本,正如我们所想的那样 他们是一个完整的阿克洛奇奥。
  3. 我们故意不把阿克洛奇奥传给“on_阿克洛奇奥” 观察者功能,因为你应该对所有的accrocchioes一视同仁 方式
  4. accrocchio的复数形式是accrocchioes
  5. 如果你使用这个库,你是故意残暴 python的禅;因此它被一个更合适的禅所取代。 只要在import accrocchio之后做import this

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java附加两个数组   java如何在Extjs的不同页面中使用相同的存储   java Jung,大顶点的布局重叠,图形出现在奇怪的位置   java如何在Android中通过画布绘制圆?   java验证库设计模式选择   java研磨机未知标记“timedTests”   java Android领域子类实例方法   java使用resteasy/jaxrs从请求负载接收两种类型的数据   缓冲策略Java缓冲策略有时不能正确绘制   java跟踪棋子   密度无关像素如何在java中锐化图像缩略图?   java如何在MongoDB更新查询中编写(或)更新   java A*寻路游戏系统退出问题   java在安卓中读取xml的最佳方式是什么?   通过反射调用的方法的java抑制警告   安卓 java。语言错误:信号11(SIGSEGV),代码10(?),故障地址006e006f   java lombok 1.18.2使用DexBuilderForDebug抛出TransformClasses   java JOptionPane CD对话框按钮?   java只返回json中的一些值,而不是完整实体对象   java包不存在错误,请稍后重试