Skip to content

Add Type Hints section to More Language Features lecture#488

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

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

Conversation

@mmcky

@mmcky mmcky commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

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

github-actions Bot commented Mar 23, 2026

Copy link
Copy Markdown

@github-actions github-actions Bot temporarily deployed to pull request March 23, 2026 00:30 Inactive
@mmcky

mmcky commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

@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

jstac commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

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

mmcky commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

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

mmcky commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author
  • do a pass of the quantecon style guide before merging. (@mmcky)

@jstac

jstac commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

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

mmcky commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

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

mmcky commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

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

mmcky commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

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

mmcky commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

@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

jstac commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Thanks @mmcky, looks good.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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).

Comment thread lectures/python_advanced_features.md Outdated
Comment thread lectures/python_advanced_features.md
Comment thread lectures/python_advanced_features.md
Comment thread lectures/python_advanced_features.md
@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

mmcky commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

\translate-resync

@mmcky

mmcky commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

✅ 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

mmcky commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

✅ 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

@mmcky

mmcky commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

\translate-resync

@mmcky

mmcky commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

✅ Translation sync completed (fa)

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

  • lectures/python_advanced_features.md

@mmcky

mmcky commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

✅ Translation sync completed (zh-cn)

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

  • lectures/python_advanced_features.md

@mmcky

mmcky commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

\translate-resync

@mmcky

mmcky commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

✅ Translation sync completed (zh-cn)

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

  • lectures/python_advanced_features.md

@mmcky

mmcky commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

✅ Translation sync completed (fa)

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

  • lectures/python_advanced_features.md

@mmcky

mmcky commented Mar 25, 2026

Copy link
Copy Markdown
Contributor Author

\translate-resync

@mmcky

mmcky commented Mar 25, 2026

Copy link
Copy Markdown
Contributor Author

✅ Translation sync completed (zh-cn)

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

  • lectures/python_advanced_features.md

@mmcky

mmcky commented Mar 25, 2026

Copy link
Copy Markdown
Contributor Author

✅ Translation sync completed (fa)

Target repo: QuantEcon/lecture-python-programming.fa
Translation PR: QuantEcon/lecture-python-programming.fa#78
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