Python 3.x 尝试创建自定义BeautifulSoup Dagster类型时出现非类型错误

Python 3.x 尝试创建自定义BeautifulSoup Dagster类型时出现非类型错误,python-3.x,beautifulsoup,dagster,Python 3.x,Beautifulsoup,Dagster,我一直在玩弄@dagster\u type并试图创建一个自定义HtmlSoup类型。基本上是围绕一个BeautifulSoup对象的奇特的@dagster_类型包装器 导入请求 从bs4导入BeautifulSoup 从dagster进口( dagster_型, 输入\u\u配置, 选择器, 领域 一串 打字检查, EventMetadataEntry ) def最大深度(汤): 如果hasattr(汤,“内容”)和soup.contents: 返回最大值([汤中子对象的最大深度(子对象))+1

我一直在玩弄
@dagster\u type
并试图创建一个自定义
HtmlSoup
类型。基本上是围绕一个BeautifulSoup对象的奇特的
@dagster_类型
包装器

导入请求
从bs4导入BeautifulSoup
从dagster进口(
dagster_型,
输入\u\u配置,
选择器,
领域
一串
打字检查,
EventMetadataEntry
)
def最大深度(汤):
如果hasattr(汤,“内容”)和soup.contents:
返回最大值([汤中子对象的最大深度(子对象))+1
其他:
返回0
def html_汤_类型_检查(值):
如果不存在(值,美化组):
返回类型检查(
成功=错误,
描述=(
'HtmlSoup应该是一个BeautifulSoup对象,got'
“{type}”
).格式(类型=类型(值))
)
如果不是hasattr(汤,“内容物”):
返回类型检查(
成功=错误,
描述=(
'HtmlSoup没有内容,请检查URL是否有内容'
)
)
返回类型检查(
成功=正确,
description='HtmlSoup Summary Stats',
元数据\u条目=[
EventMetadataEntry.text(
str(最大深度(值)),
“最大深度”,
“页面的最大嵌套深度”
),
EventMetadataEntry.text(
str(set(value.find_all())中标记的tag.name),
“标记名称”,
'页面中所有可用的标记'
)
]
)
@输入\u\u配置(
选择器(
{
“url”:字段(
一串
is_optional=False,
描述=(
'要摄取并转换为汤对象的URL'
)
)
}
)
)
def html_汤_输入_水合作用_配置(上下文,选择器):
url=选择器['url']
res=requests.get(url,参数={
“内容类型”:“文本/html”
})
如果(非资源状态_代码==200):
返回类型检查(
成功=错误,
描述=(
“{status_code}错误,请检查URL:{URL}是否正确”
).format(状态码=res.status码,url=url)
)
soup=BeautifulSoup(res.content,'html.parser')
返回HtmlSoup(汤)
@dagster_型(
name='HtmlSoup',
描述=(
'从存储在中的URL提取的HTML'
“一个美丽的群体对象。”
),
类型检查=html类型检查,
input\u hydration\u config=html\u soup\u input\u hydration\u config
)
类HtmlSoup(美化组):
通过
是我一直在尝试的,但每当我尝试调用一个实体时,它使用一个
HtmlSoup
类型作为输入,例如

@solid
def get_url(上下文,汤:HtmlSoup):
退回汤中的食物
我得到这个错误

TypeError:“非类型”对象不可调用

  File "/Users/John/Documents/.../venv/lib/python3.7/site-packages/dagster/core/engine/engine_inprocess.py", line 241, in dagster_event_sequence_for_step
    for step_event in check.generator(_core_dagster_event_sequence_for_step(step_context)):
  File "/Users/John/Documents/.../venv/lib/python3.7/site-packages/dagster/core/engine/engine_inprocess.py", line 492, in _core_dagster_event_sequence_for_step
    for input_name, input_value in _input_values_from_intermediates_manager(step_context).items():
  File "/Users/John/Documents/.../venv/lib/python3.7/site-packages/dagster/core/engine/engine_inprocess.py", line 188, in _input_values_from_intermediates_manager
    step_context, step_input.config_data
  File "/Users/John/Documents/.../venv/lib/python3.7/site-packages/dagster/core/types/config_schema.py", line 73, in construct_from_config_value
    return func(context, config_value)
  File "/Users/John/Documents/.../custom_types/html_soup.py", line 82, in html_soup_input_hydration_config
    return HtmlSoup(soup)
  File "/Users/John/Documents/.../venv/lib/python3.7/site-packages/bs4/__init__.py", line 286, in __init__
    markup = markup.read()
我得到一些额外的信息说

执行过程中引发异常,该异常可能是框架错误,而不是用户代码中的错误。
原始错误消息:TypeError:“非类型”对象不可调用
我一直在深入研究
@dagster\u type
装饰器的内部结构,以及
@input\u\u config
装饰器的工作原理,但到目前为止,我还是有点不知所措


感谢所有的帮助

我实际上能够通过使用文档中描述的
as_dagster_type
方法来解决这个问题

HtmlSoup=as\u dagster\u类型(
美丽的乌苏,
name='BeautifulSoupHTML',
描述=“”
漂亮的汤HTML对象
''',
input\u hydration\u config=html\u soup\u input\u hydration\u config,
类型检查=html类型检查
)