Skip to content

Add comprehensive type annotations and Python 3 modernization - #67

Merged
letmaik merged 7 commits into
masterfrom
copilot/add-typing-support-tests
Jan 30, 2026
Merged

Add comprehensive type annotations and Python 3 modernization#67
letmaik merged 7 commits into
masterfrom
copilot/add-typing-support-tests

Conversation

Copilot AI commented Jan 30, 2026

Copy link
Copy Markdown
Contributor

Adds comprehensive type annotations to the Cython source file (_lensfun.pyx) to match the approach in rawpy PR #275. This complements the existing .pyi stub file with runtime-visible type information.

Changes

Typing imports

  • Added from typing import Optional, List, Union, Any
  • Added from numpy.typing import NDArray

Full type annotations

  • Parameter type annotations on all methods: maker: Optional[str], loose_search: bool, etc.
  • Return type annotations on all methods and properties
  • Database methods: find_cameras() -> List[Camera], find_lenses() -> List[Lens], etc.
  • Lens interpolation methods: -> Optional[LensCalibDistortion], etc.
  • Modifier apply methods: -> Optional[NDArray[np.float32]] for coordinate arrays, -> bool for color modification

Modern property syntax

  • Converted all 34 properties from legacy property abc: syntax to modern @property decorator
  • Added return type annotations to all properties (e.g., @property def maker(self) -> str:)
  • Properties now use direct return statements instead of __get__ methods

Python 3 modernization

  • Added language_level=3 directive to make code Python 3 only
  • Removed legacy _chars function (Python 2 compatibility code)
  • With c_string_type=unicode and language_level=3, Cython automatically handles str→char* conversion with UTF-8 encoding
  • Simplified code by removing manual string encoding calls

Example

import lensfunpy
import numpy as np

db = lensfunpy.Database()
cameras = db.find_cameras('NIKON', 'D3S')  # List[Camera] with full type info

# Modern property access with type information
cam = cameras[0]
maker: str = cam.maker  # Type checker knows this is str
crop: float = cam.crop_factor  # Type checker knows this is float

lens = db.find_lenses(cam, 'Nikon')[0]
mod = lensfunpy.Modifier(lens, cam.crop_factor, 1000, 1000)
mod.initialize(28.0, 2.8)

coords = mod.apply_geometry_distortion()  # Optional[NDArray[np.float32]]
if coords is not None:
    print(coords.shape)

The inline types and modern property syntax improve IDE experience and make type information visible in the compiled module's introspection. The code is now Python 3 only and follows current Cython best practices.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits January 30, 2026 00:23
…NIFEST.in, setup.py, and type tests

Co-authored-by: letmaik <530988+letmaik@users.noreply.github.com>
Co-authored-by: letmaik <530988+letmaik@users.noreply.github.com>
…er type, fix typo

Co-authored-by: letmaik <530988+letmaik@users.noreply.github.com>
Copilot AI changed the title [WIP] Add typing support and tests for project Add type annotations and PEP 561 compliance Jan 30, 2026
Copilot AI requested a review from letmaik January 30, 2026 00:35
Co-authored-by: letmaik <530988+letmaik@users.noreply.github.com>
Copilot AI changed the title Add type annotations and PEP 561 compliance Add inline type annotations to _lensfun.pyx Jan 30, 2026
@letmaik

letmaik commented Jan 30, 2026

Copy link
Copy Markdown
Owner

@copilot change all legacy property abc: syntax to the modern @property syntax that cython supports, and add return types then to those.

…or with return types

Co-authored-by: letmaik <530988+letmaik@users.noreply.github.com>

Copilot AI commented Jan 30, 2026

Copy link
Copy Markdown
Contributor Author

@copilot change all legacy property abc: syntax to the modern @property syntax that cython supports, and add return types then to those.

Converted all 34 properties from legacy property abc: syntax to modern @property decorator with return type annotations. Commit: dcf1a89

Copilot AI changed the title Add inline type annotations to _lensfun.pyx Add inline type annotations and modernize properties in _lensfun.pyx Jan 30, 2026
Comment thread lensfunpy/_lensfun.pyx Outdated
…tations

Co-authored-by: letmaik <530988+letmaik@users.noreply.github.com>
Copilot AI changed the title Add inline type annotations and modernize properties in _lensfun.pyx Add comprehensive type annotations and Python 3 modernization Jan 30, 2026
Copilot AI requested a review from letmaik January 30, 2026 01:11
@letmaik
letmaik marked this pull request as ready for review January 30, 2026 08:28
@letmaik
letmaik merged commit 609d629 into master Jan 30, 2026
56 checks passed
@letmaik
letmaik deleted the copilot/add-typing-support-tests branch January 30, 2026 09:55
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.

2 participants