Skip to content

Ensure the SensorConfig.material is actually a material when possible.#2852

Merged
kif merged 3 commits into
silx-kit:mainfrom
kif:2851_SensorConfig
May 10, 2026
Merged

Ensure the SensorConfig.material is actually a material when possible.#2852
kif merged 3 commits into
silx-kit:mainfrom
kif:2851_SensorConfig

Conversation

@kif
Copy link
Copy Markdown
Member

@kif kif commented May 4, 2026

close #2851

@kif kif added the ready to merge Please review label May 4, 2026
@kif kif requested a review from EdgarGF93 May 4, 2026 06:46
from math import exp
from collections import namedtuple
import numpy
from typing import ClassVar
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If you import anyways typing, you could consider import of Union and Optional

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Makes sense ... I dislike Union and it is no more recommended since 3.10.

@dataclass
class SensorConfig:
"class for configuration of a sensor"
material: SensorMaterial|str
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This would become:
material: Union[SensorMaterial, str]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

| replaces in a simpler way Union since 3.10

Comment thread src/pyFAI/detectors/sensors.py Outdated
@@ -169,6 +169,12 @@
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

thickness: Optional[float] = None



@dataclass
class SensorConfig:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would it make sense to use here actually the frozen decorator? @kif

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Daclasses in pyFAI are slotted ... so not really extendible. That said, frozen dataclasses could make sense.
On the other hand, for frozen object, I would rather use NamedTuple rather than dataclasses that provide non-mutability with better performances.

@kif kif merged commit e0478aa into silx-kit:main May 10, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready to merge Please review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SensorConfig class equality comparison fails if material type is not defined the same way in both instances

2 participants