google / google/python-fire

not compatible with pydantic.validate_arguments

Đang mở
#402 4 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
Python
Star
28.2k
Fork
1.5k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

A function with `Field` parameter wrapped by `pydantic.validate_arguments`, can not been exeuted from the command line.

```py
from datetime import datetime
from pydantic import Field, validate_arguments

@validate_arguments()
def foo(dt: datetime = Field(default_factory=datetime.now)):
print(dt)

if __name__ == '__main__':
import fire
fire.Fire(foo)
```

run this code from command line with raise:

```
Traceback (most recent call last):
File "/home/xxx/repositories/others/test_fire.py", line 12, in
fire.Fire(foo)
File "/home/xxx/.conda/envs/py39/lib/python3.9/site-packages/fire/core.py", line 141, in Fire
component_trace = _Fire(component, args, parsed_flag_args, context, name)
File "/home/xxx/.conda/envs/py39/lib/python3.9/site-packages/fire/core.py", line 466, in _Fire
component, remaining_args = _CallAndUpdateTrace(
File "/home/xxx/.conda/envs/py39/lib/python3.9/site-packages/fire/core.py", line 681, in _CallAndUpdateTrace
component = fn(*varargs, **kwargs)
File "pydantic/decorator.py", line 40, in pydantic.decorator.validate_arguments.validate.wrapper_function
from contextlib import _GeneratorContextManager
File "pydantic/decorator.py", line 133, in pydantic.decorator.ValidatedFunction.call
func.__dict__.update(kw)
File "pydantic/decorator.py", line 130, in pydantic.decorator.ValidatedFunction.init_model_instance
else:
File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for Foo
dt
invalid type; expected datetime, string, bytes, int or float (type=type_error)

```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.