Skip to content

Add typing generics#4131

Open
schnellerhase wants to merge 17 commits intoschnellerhase/mypy-demo/testfrom
schnellerhase/generics
Open

Add typing generics#4131
schnellerhase wants to merge 17 commits intoschnellerhase/mypy-demo/testfrom
schnellerhase/generics

Conversation

@schnellerhase
Copy link
Copy Markdown
Contributor

@schnellerhase schnellerhase commented Mar 19, 2026

Extends the approach of #4094 for multi export type wrappers to

  • Vector
  • MatrixCSR
  • SuperLUDistMatrix
  • SuperLUDistSolver
  • DirichletBC
  • CoordinateElement
  • FiniteElement
  • Form
  • Constant
  • Expression
  • Function
  • FunctionSpace
  • Mesh
  • Geometry
  • CoordinateElement
  • BoundingBoxTree
  • PointOwnershipData

Depends on #4135

@schnellerhase schnellerhase changed the title Add trying generics Add typing generics Mar 19, 2026
@schnellerhase schnellerhase force-pushed the schnellerhase/generics branch 10 times, most recently from b5f116f to 37b3898 Compare March 19, 2026 13:50
@jhale
Copy link
Copy Markdown
Member

jhale commented Mar 19, 2026

Looks good - have you considered directly mimicking the naming/setup of the C++ concepts? Perhaps they could also be put somewhere more general for use across the whole interface.

https://github.com/FEniCS/dolfinx/blob/main/cpp/dolfinx/common/types.h#L26

@schnellerhase schnellerhase force-pushed the schnellerhase/generics branch from 1cde704 to 6d5be09 Compare March 20, 2026 07:21
@schnellerhase schnellerhase changed the base branch from main to schnellerhase/mypy-demo/test March 23, 2026 14:59
@schnellerhase schnellerhase force-pushed the schnellerhase/generics branch 2 times, most recently from bcf403b to f0a843a Compare March 24, 2026 17:33
@schnellerhase schnellerhase added type-hints python Pull requests that update Python code labels Mar 24, 2026
@schnellerhase
Copy link
Copy Markdown
Contributor Author

Looks good - have you considered directly mimicking the naming/setup of the C++ concepts? Perhaps they could also be put somewhere more general for use across the whole interface.

https://github.com/FEniCS/dolfinx/blob/main/cpp/dolfinx/common/types.h#L26

AFAIK the python typing currently does not allow conditional type deductions, so we can not mimic any scalar/real type concepts.

@schnellerhase schnellerhase self-assigned this Mar 24, 2026
@schnellerhase schnellerhase marked this pull request as ready for review March 24, 2026 17:54
@jhale
Copy link
Copy Markdown
Member

jhale commented Mar 25, 2026

I think you're overcomplicating it a bit. My basic point is to add a dolfinx.typing module where you add meaningful definitions of e.g. _Scalar and _Float using TypeVar and then import them uniformly for use elsewhere. Perhaps some modules where the definition is isolated (e.g. MeshTags) the current design is appropriate.

@schnellerhase schnellerhase force-pushed the schnellerhase/generics branch from 36886a4 to 5944836 Compare March 31, 2026 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests that update Python code type-hints

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants