Closed annehaley closed 9 months ago
@manthey Most of the typing changes in this PR were straightforward, but there was one variety of error that seemed to indicate a bigger problem. There are still 21 errors similar to the following:
Argument "file" to "Project" has incompatible type "Path"; expected "FileType[Literal['core.Project.file']]
For every place that we passed a Path
or a string to a field that was typed as FileType
, this type error occured. We got away with this in the previous version, but the latest version strongly discourages changing the type of v
in the validate
function: https://github.com/pydantic/pydantic/discussions/3997
How do you think we should approach changing the way we set these fields?
I was getting similar errors for NonEmptyString
as for FieldType
. The coercion we had been relying on was no longer accepted:
Argument "anatomy_type" to "Segmentation" has incompatible type "str"; expected "NonEmptyString"
Resolves #351. This is related to the current failure on #355, which contains the following traceback:
Inevitably, with the update to mypy, the type coercion we had been performing for
FileType
objects in SWCC is no longer allowed, so this typing update will introduce breaking changes.The SWCC
ApiModel
now separates File fields from their source fields, where the source field is typed asUnion[str, Path]
. For every file-type field on an SWCC class, a_source
suffix should be added to the attribute when calling the constructor. For example,project = Project(file=file_path)
becomesproject = Project(file_source=file_path)
. After this constructor change has been made,project.file
is still accessible and will return aFile
object with attributespath
,url
,field_id
, andfield_value
. This accessor to theFile
object is generated dynamically inApiModel.__getattribute__
.