Skip to content

Add Type Hints section to More Language Features lecture#488

Merged
mmcky merged 6 commits intomainfrom
add-type-hints-section
Mar 23, 2026
Merged

Add Type Hints section to More Language Features lecture#488
mmcky merged 6 commits intomainfrom
add-type-hints-section

Conversation

@mmcky
Copy link
Contributor

@mmcky mmcky commented Mar 23, 2026

Summary

Adds a compact new section on Python type hints to the More Language Features lecture, placed between the Operators section and Decorators.

Content

  • Basic Syntax: annotating function parameters, return types, and variables
  • Common Types: table of built-in types plus container type syntax
  • Hints Do Not Enforce Types: demonstration that Python ignores type hints at runtime
  • Why Use Type Hints: readability, IDE support, error checking tools, LLM-generated code
  • Type Hints in Scientific Python: connection to JAX/Numba and JIT compilation concepts

Design Decisions

  • Kept minimal (~100 lines) to avoid overwhelming new Python programmers
  • Added as a section (not a full lecture), per discussion in the issue
  • Cross-references the existing dynamic typing discussion in need_for_speed
  • All code cells execute successfully in the Jupyter Book build

Closes #343

mmcky added 2 commits March 23, 2026 11:12
Adds a compact section on Python type hints to the python_advanced_features
lecture, covering:
- Basic syntax (function parameters, return types, variable annotations)
- Common built-in types and container type syntax
- Demonstration that hints are not enforced at runtime
- Why type hints matter (readability, IDE support, error checking, LLM code)
- Connection to scientific Python and JIT compilation

Closes #343
@github-actions
Copy link

github-actions bot commented Mar 23, 2026

@github-actions github-actions bot temporarily deployed to pull request March 23, 2026 00:30 Inactive
@mmcky
Copy link
Contributor Author

mmcky commented Mar 23, 2026

@jstac I think this is a nice (small) addition that captures the essence of your excellent comment in #343

@mmcky mmcky requested a review from jstac March 23, 2026 00:56
@jstac
Copy link
Contributor

jstac commented Mar 23, 2026

Very nice :-)

BTW, I remember that last year the PRs were listing changed lectures (links to deployment lectures), making it easier to click through and see changes. Is that infrastructure still available?

@mmcky
Copy link
Contributor Author

mmcky commented Mar 23, 2026

nice catch @jstac -- it looks like I haven't updated lecture-python-programming.

QuantEcon/meta#296

Direct lecture linking is in python.quantecon.org repo (but not here).

I'll roll out our quantecon/actions/netlify-preview action across the board.

LGTM.

@mmcky
Copy link
Contributor Author

mmcky commented Mar 23, 2026

  • do a pass of the quantecon style guide before merging. (@mmcky)

@jstac
Copy link
Contributor

jstac commented Mar 23, 2026

Thanks @mmcky

Is there a way to automate this across the repos, along with updates to styles etc?

Is it worth revisiting the one-big-repo idea?

Just tossing ideas around -- I don't really know the upsides and downsides...

@mmcky
Copy link
Contributor Author

mmcky commented Mar 23, 2026

Thanks @mmcky

Is there a way to automate this across the repos, along with updates to styles etc?

Is it worth revisiting the one-big-repo idea?

Just tossing ideas around -- I don't really know the upsides and downsides...

thanks @jstac

I am actually running this PR over https://github.com/quantEcon/action-style-guide right now as a test case.

This automation is still in work -- too much noise (I don't want to add noise -- only value).

mmcky added 2 commits March 23, 2026 13:23
Lowercase section headings to capitalize only the first word and proper
nouns (e.g., Python), per QuantEcon style rules.
Apply sentence case to all section headings (##, ###, ####) across the
entire lecture, not just the new Type Hints section. Only the first word
and proper nouns (e.g., Python) are capitalized.
@mmcky
Copy link
Contributor Author

mmcky commented Mar 23, 2026

Applied qe-writing-006 (sentence-case headings) across the entire lecture — not just the new Type Hints section. Fixed 14 headings total to capitalize only the first word and proper nouns.

@github-actions github-actions bot temporarily deployed to pull request March 23, 2026 02:33 Inactive
Change bold to italic for emphasis (not definitions):
- 'skip it on first pass' (pre-existing)
- 'ignored by the Python interpreter at runtime'
- 'not enforced'
- 'clarity and tooling support'
@mmcky
Copy link
Contributor Author

mmcky commented Mar 23, 2026

Style fix (qe-writing-005): Changed bold to italic in 4 places where formatting was used for emphasis rather than definitions:

  • L25: skip it on first pass (pre-existing)
  • Note box: ignored by the Python interpreter at runtime
  • Type hints section: not enforced
  • Type hints section: clarity and tooling support

Bold remains for the **type hints** definition and the numbered list labels (**Readability**, **Editor support**, etc.) which serve as definition-style labels.

@mmcky
Copy link
Contributor Author

mmcky commented Mar 23, 2026

@jstac this looks good to me now. I'll merge this. thanks for casting an eye over it.

@github-actions github-actions bot temporarily deployed to pull request March 23, 2026 02:44 Inactive
@jstac
Copy link
Contributor

jstac commented Mar 23, 2026

Thanks @mmcky, looks good.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new, compact “Type hints” section to the More Language Features lecture, positioned between the */** operators content and the decorators section, to introduce annotations and their practical benefits in scientific Python.

Changes:

  • Introduces a new “Type hints” section covering syntax, common types, and runtime behavior.
  • Adds a short discussion of why type hints are useful (readability, tooling, static checkers, LLM-generated code).
  • Updates various headings/emphasis around the insertion point (capitalization/styling).

@github-actions github-actions bot temporarily deployed to pull request March 23, 2026 03:38 Inactive
@mmcky mmcky merged commit f791129 into main Mar 23, 2026
5 checks passed
@mmcky mmcky deleted the add-type-hints-section branch March 23, 2026 04:00
@mmcky
Copy link
Contributor Author

mmcky commented Mar 23, 2026

\translate-resync

@mmcky
Copy link
Contributor Author

mmcky commented Mar 23, 2026

✅ Translation sync completed (zh-cn)

Target repo: QuantEcon/lecture-python-programming.zh-cn
Translation PR: QuantEcon/lecture-python-programming.zh-cn#2
Files synced (1):

  • lectures/python_advanced_features.md

@mmcky
Copy link
Contributor Author

mmcky commented Mar 23, 2026

✅ Translation sync completed (fa)

Target repo: QuantEcon/lecture-python-programming.fa
Translation PR: QuantEcon/lecture-python-programming.fa#69
Files synced (1):

  • lectures/python_advanced_features.md

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.

[New Lecture] Python Static Typing

3 participants