Skip to content

Modernize Python code to 3.10+ idioms and add type hints#34

Merged
ardiloot merged 4 commits intomasterfrom
modernize-python
Feb 19, 2026
Merged

Modernize Python code to 3.10+ idioms and add type hints#34
ardiloot merged 4 commits intomasterfrom
modernize-python

Conversation

@ardiloot
Copy link
Copy Markdown
Owner

  • Add type hints to all Python function signatures
  • Replace % string formatting with f-strings
  • Use argumentless super() (Python 3+)
  • Use modern class syntax (class Foo: instead of class Foo(object):)
  • Replace os.path with pathlib.Path
  • Use context managers for file handles
  • Replace type() == with isinstance()
  • Replace pylab with matplotlib.pyplot
  • Replace scipy.real/imag with np.real/np.imag
  • Replace float('inf') with math.inf
  • Replace np.arange with range() for loop indexing
  • Use specific exception types instead of bare Exception
  • Remove Eclipse/PyDev IDE comments
  • Remove dead if __name__ == '__main__': pass blocks
  • Add __all__ to NonlinearTMM/__init__.py
  • Clean up docs/conf.py (remove encoding comment, update master_doc to root_doc)
  • Add .vscode/settings.json

- Add _SecondOrderNLTMMCython.pyi with full type stubs for all Cython
  extension classes: _Chi2Tensor, Material, _Wave, _Intensities,
  _SweepResultNonlinearTMM, _WaveSweepResultNonlinearTMM, _FieldsZ,
  _FieldsZX, _HomogeneousWave, _NonlinearLayer, NonlinearTMM,
  _SecondOrderNLIntensities, _SweepResultSecondOrderNLTMM,
  _WaveSweepResultSecondOrderNLTMM, and SecondOrderNLTMM
- Add __init__.pyi re-exporting all public and private types
- Add missing type annotations to 9 methods in _TmmForWavePackets.py
- Add type hints to helper functions in test_TMM.py and test_SPDC.py
- Add return type annotations to example script functions
@ardiloot ardiloot merged commit 2929b22 into master Feb 19, 2026
11 checks passed
@ardiloot ardiloot deleted the modernize-python branch February 19, 2026 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant