Skip to content

Conversation

@SimonHeybrock
Copy link
Member

This fixes a couple of problems with the new addition from #75, found when rolling this out to ESSsans (see scipp/esssans#160).

Comment on lines 155 to 160
class Filename(sciline.Scope[RunType, Path], Path): ...


@dataclass
class Filename(Generic[RunType]):
class NeXusFileSpec(Generic[RunType]):
value: FilePath | NeXusFile | NeXusGroup
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jl-wynen Wondering what you think about this. My latest attempt to have both, Union-type and (generic) type alias, by splitting it into two parts. For the common user there is a helper that forwards Filename into NeXusFileSpec.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course it does not solve the str | Path issue, unless we split the types and helpers further.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super happy because this adds another node to the graph.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you can guess this is due to lack of better options. Do you have any?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could duplicate the (current 4) providers that turn NeXusFileSpec into NeXusLocationSpec. Then the extra node is gone. Is that better?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you can guess this is due to lack of better options. Do you have any?

Drop Filename and auto-convert parameters to their key type on insertion. This would mean that

pl[NeXusFileSpec] = 'some/path'

produces the expected NeXusFileSpec object.

I suggested this in the past but you decided against it in favour of duck-typing. I think that this precludes us from supporting static type checkers without workarounds like you implemented here.

On a side note, what we really want here is a sum-type that works both at runtime and makes mypy happy. I have been trying to create one several times but have been unsuccessful.

Copy link
Member Author

@SimonHeybrock SimonHeybrock Aug 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, we should consider your suggestion again. But as that is not a quick or easy solution, are you ok with keeping it as it is for now?

Component = TypeVar('Component', bound=snx.NXobject)


class Filename(sciline.Scope[RunType, Path], Path): ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this, there are now to Filename types. The other one is in types.py. This seems confusing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see #75 (comment), this is the case for about 20 or so types.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See me new comment

@SimonHeybrock SimonHeybrock merged commit 232d7db into main Aug 26, 2024
@SimonHeybrock SimonHeybrock deleted the nexus-fixes branch August 26, 2024 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants