Skip to content

Add inline type hints for public API#153

Merged
beaufour merged 13 commits into
masterfrom
type-stubs
Jan 24, 2026
Merged

Add inline type hints for public API#153
beaufour merged 13 commits into
masterfrom
type-stubs

Conversation

@beaufour

Copy link
Copy Markdown
Collaborator

Summary

  • Adds inline type hints to the public API modules for IDE autocompletion and static type checking
  • Adds py.typed marker for PEP 561 compliance
  • Adds mypy and types-requests to dev dependencies

Closes #127

Changes

Typed modules:

  • flickrerrors.py - Exception classes
  • keys.py - set_keys() and module variables
  • auth.py - AuthHandler, OAuthRequest, token_factory(), set_auth_handler()
  • method_call.py - enable_cache(), disable_cache(), set_timeout(), get_timeout()
  • upload.py - upload(), replace()
  • objects.py - Base classes (FlickrObject, FlickrList, Walker, SlicedWalker) and domain classes (Person, Photo, Photoset, Gallery, Group, Tag)

New files:

  • flickr_api/py.typed - PEP 561 marker

Design decisions

  • Inline types instead of .pyi stub files since Python 3.10+ is already required
  • Pragmatic strictness - typed what's knowable, used Any for dynamic API responses
  • Public API scope - focused on user-facing exports, minimal fixes to internal modules

Test plan

  • uv run mypy flickr_api/ --ignore-missing-imports passes (0 errors)
  • uv run pytest passes (237 tests)
  • Integration tests pass (106/109, 3 skipped)
  • py.typed included in wheel distribution

🤖 Generated with Claude Code

beaufour and others added 13 commits January 24, 2026 15:06
Documents the approach for adding inline type hints to the public API
to address issue #127.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Detailed step-by-step plan for adding inline type hints to the public API.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add class attribute annotations and __init__ type hints to:
- FlickrAPIError: code (int), message (str)
- FlickrServerError: status_code (int), content (str)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Type all classes and functions in auth.py:
- AuthHandler class with class attributes and all methods
- OAuthRequest class with all dunder methods
- Module-level functions token_factory and set_auth_handler

Added necessary type narrowing checks for mypy compliance.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add comprehensive type annotations to the core infrastructure classes:
- FlickrObject: Base class with typed converters, display, and all methods
- FlickrList: Typed as UserList[FlickrObject] with info attribute
- Walker: Generic[T] iterator for paginated results
- SlicedWalker: Generic[T] for sliced iteration

Uses TypeVar T bound to FlickrObject for generic walker typing.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add class-level type annotations for commonly-accessed attributes to main
domain classes (Person, Photo, Photoset, Gallery, Group, Tag) and type
the dict_converter helper function.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add minimal type annotations to cache.py, reflection.py, and api.py
to allow full mypy pass on the package.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@beaufour beaufour merged commit 8d8c213 into master Jan 24, 2026
@beaufour beaufour deleted the type-stubs branch January 24, 2026 21:25
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.

type stubs?

1 participant