将许多变量转换成用于

问题描述

我正在研究将一大堆函数彼此之间传递基本相同的东西,以创建从pydantic的BaseModel派生的对象并将它们作为函数参数传递。由于pydantic是一个相对较新的事物,因此我在想这是一个好主意以及在反馈到此大规模重构之前是否有任何反馈。

基本上看起来像这样,

  cupertino_icons: ^0.1.3
  splashscreen:
  provider:
  route_transitions:
  flutter_vector_icons:
  simple_animations:
  supercharged:
  animated_background:
  sqflite:
  path:
  toggle_switch:
  firebase_auth:
  firebase_core:
  cloud_firestore:
  image_picker:
  shared_preferences:
  cached_network_image:
  firebase_storage:
  google_sign_in:
  flutter_facebook_auth:
  draggable_widget:
  enum_to_string:
  stacked:
  auto_route:
  stacked_services:
  get_it:
  injectable:

而不是像这样的一堆东西(深度超过12层)

from pydantic import BaseModel

class New(BaseModel):
    a_str: str = 'foo'
    a_dict: dict

def do_first_things(n: New) -> New:
    n.a_dict.update({'foo': 'bar'})
    n = do_more_things(n)
    return n

def do_more_things(n: New) -> New:
    n.a_str = 'bar'
    return n

new = New(
    a_dict={'foo': 'baz'}
)
print(new)
new = do_first_things(new)
print(new)

我只是没有看到任何地方这样做,并认为通过这样做,我在表达函数逻辑时基本上有了def first_func(a_str,a_dict,...): second_func(a_str,a_dict) def second_func(a_str,...): ... 的概念。

非常感谢您的任何反馈!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)